Requirements: The program will not be executed when the time is between 0:00 and 0:50 am.
That is, it is necessary to determine whether the current time point is between 00:00:00 and 00:05:00
method:
Java code:
/** * Determine whether the time is within the time period* * @param date * Current time yyyy-MM-dd HH:mm:ss * @param strDateBegin * Start time 00:00:00 * @param strDateEnd * End time 00:05:00 * @return */ public static boolean isInDate(Date date, String strDateBegin, String strDateEnd) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String strDate = sdf.format(date); // intercept the current time, minute and second int strDateH = Integer.parseInt(strDate.substring(11, 13)); int strDateM = Integer.parseInt(strDate.substring(14, 16)); int strDateS = Integer.parseInt(strDate.substring(17, 19)); // intercept the start time, minute and second int strDateBeginH = Integer.parseInt(strDateBegin.substring(0, 2)); int strDateBeginM = Integer.parseInt(strDateBegin.substring(3, 5)); int strDateBeginS = Integer.parseInt(strDateBegin.substring(6, 8)); // Intercept the end time, minute and second, int strDateEndH = Integer.parseInt(strDateEnd.substring(0, 2)); int strDateEndM = Integer.parseInt(strDateEnd.substring(3, 5)); int strDateEndS = Integer.parseInt(strDateEnd.substring(6, 8)); if ((strDateH >= strDateBeginH && strDateH <= strDateEndH)) { // The current time and hours are between the start time and the end time hours if (strDateH > strDateBeginH && strDateH < strDateEndH) { return true; // The current time and hours are equal to the start time and hours, and the minutes are between the start and the end} else if (strDateH == strDateBeginH && strDateM >= strDateBeginM && strDateM <= strDateEndM) { return true; // The current time and hours are equal to the start time and hours, and the minutes are equal to the start time and minutes, and the seconds are between the start and the end} else if (strDateH == strDateBeginH && strDateM == strDateBeginM && strDateS >= strDateBeginS && strDateS <= strDateEndS) { return true; } // The current time and hours are large equal to the start time and hours, the end time and hours are equal to the end time and minutes are small equal to the end time and minutes are small equal to the end time and seconds are small else if (strDateH >= strDateBeginH && strDateH == strDateEndH && strDateM <= strDateEndM) { return true; // The current time and hours are large equal to the start time and hours, the end time and hours are equal to the end time and seconds are small equal to the end time and seconds are small} else if (strDateH >= strDateBeginH && strDateH == strDateEndH && strDateM == strDateEndM && strDateS <= strDateEndS) { return true; } else { return false; } } else { return false; } }Thank you for reading, I hope it can help you. Thank you for your support for this site!