Here you can find the source of getTaskTrigger(int taskTriggerHour, boolean tomorrow)
Parameter | Description |
---|
public static Date getTaskTrigger(int taskTriggerHour, boolean tomorrow)
//package com.java2s; import java.util.Calendar; import java.util.Date; import java.util.TimeZone; public class Main { /**// ww w. jav a 2s. c o m * Get date of next time for triggering task * @param taskTriggerHour: hour of triggering task * @return Date of next trigger */ public static Date getTaskTrigger(int taskTriggerHour, boolean tomorrow) { return getTaskTrigger(taskTriggerHour, 0, tomorrow); } /** * Get date of next time for triggering task * @param taskTriggerHour: hour of triggering task * @param taskTriggerMinute: minutes of triggering task * @return Date of next trigger */ public static Date getTaskTrigger(int taskTriggerHour, int taskTriggerMinute, boolean tomorrow) { // change to start from given time Calendar cal = getCalendar(); cal.set(Calendar.HOUR_OF_DAY, taskTriggerHour); cal.set(Calendar.MINUTE, taskTriggerMinute); if (tomorrow) { cal.add(Calendar.DAY_OF_YEAR, 1); } else { /* int curHour = cal.get(Calendar.HOUR_OF_DAY); int curMinute = cal.get(Calendar.MINUTE); if ((curHour > taskTriggerHour) || ((curHour == taskTriggerHour) && (curMinute > taskTriggerMinute))) { cal.add(Calendar.MINUTE, 2); } */ } return cal.getTime(); } /** * Get calendar instance with default time zone of GMT+8 * @return Calendar instance */ public static Calendar getCalendar() { TimeZone.setDefault(getDefaultTimeZone()); return Calendar.getInstance(); } /** * Get default time zone of China * @return default time zone */ public static TimeZone getDefaultTimeZone() { return TimeZone.getTimeZone("GMT+8"); } }