Calendar类 Calendar.HOUR(12小时制) 和 Calendar.HOUR_OF_DAY(24小时制)

今天发现调度器设置成上午的时间执行,下午的时间不执行。

查看代码发现:

Calendar.HOUR_OF_DAY (24小时)设置成 <span style="font-family: Arial, Helvetica, sans-serif;">Calendar.HOUR (12小时)造成的。时间不对</span>

int interval = 1; //间隔事件
			int repeat = 0; //调度任务的执行次数 o代表循环
			String time = ftpProperties.getExecTime();
			int hour = 0;
			int minute = 0;
			if(time != null && !time.equals("")){
				String[] ts = time.split(":");
				hour = Integer.parseInt(ts[0]);
				minute = Integer.parseInt(ts[1]);
			}
			Calendar startTime = Calendar.getInstance();
			if(startTime.get(Calendar.HOUR_OF_DAY) > hour || (startTime.get(Calendar.HOUR_OF_DAY) == hour && startTime.get(Calendar.MINUTE) > minute)){
				startTime.setTimeInMillis(startTime.getTimeInMillis() + 24 * 60 * 60 * 1000);
			}
			startTime.set(Calendar.HOUR_OF_DAY, hour);
			startTime.set(Calendar.MINUTE, minute);
			startTime.set(Calendar.SECOND, 0);
			ScheduleIterator iterator = new DefaultScheduleIterator(startTime, Calendar.DATE, interval, repeat);




/**
     * 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;


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值