今天发现调度器设置成上午的时间执行,下午的时间不执行。
查看代码发现:
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;