获取当天截止时刻 踩坑

这篇博客介绍了Java中使用Calendar API设置当天结束时间的方法。通过设置小时为23,分钟、秒和毫秒为最大值,获取当天23:59:59.999的时刻,转化为秒数。主要涉及的时间字段包括HOUR和HOUR_OF_DAY,区分了12小时制和24小时制。
摘要由CSDN通过智能技术生成
/**
 * Field number for <code>get</code> and <code>set</code> indicating the
 * hour of the morning or afternoon. <code>HOUR</code> is used for the
 * 12-hour clock (0 - 11). Noon and midnight are represented by 0, not by 12.
 * E.g., at 10:04:15.250 PM the <code>HOUR</code> is 10.
 *
 * @see #AM_PM
 * @see #HOUR_OF_DAY
 */
public final static int HOUR = 10;

/**
 * Field number for <code>get</code> and <code>set</code> indicating the
 * hour of the day. <code>HOUR_OF_DAY</code> is used for the 24-hour clock.
 * E.g., at 10:04:15.250 PM the <code>HOUR_OF_DAY</code> is 22.
 *
 * @see #HOUR
 */
public final static int HOUR_OF_DAY = 11;

    /**
    * 当天的结束时间
    * 单位秒
    * @return
    */
   public static Integer getTodayEndTime() {
       Calendar todayEnd = Calendar.getInstance();

//    todayEnd.set(Calendar.HOUR, 23);
      todayEnd.set(Calendar.HOUR_OF_DAY, 23); 

      todayEnd.set(Calendar.MINUTE, 59);

      todayEnd.set(Calendar.SECOND, 59);

      todayEnd.set(Calendar.MILLISECOND, 999);

      return Convert.toInt(todayEnd.getTime().getTime()/1000);

   }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值