java—Determine whether the current time (in days) is between two time periods

Reference: https://blog.csdn.net/lihua5419/article/details/80625114

Current time: 15:00, judge whether it is between 3:00 and 16:00

import java.util.Date;
import java.text.SimpleDateFormat;


public class date3 {
    public static void main(String[] args) {
        SimpleDateFormat dateFormater = new SimpleDateFormat("HHmm");
        String date = dateFormater.format(new Date());
        System.out.println(date);
        int time = Integer.parseInt(date);
        if (time > 300 && time < 1600) {
            System.out.println("在时间段内");
        } else {
            System.out.println ( "Not within this time period" ); 
        } 
    } 
}

 

Guess you like

Origin www.cnblogs.com/erchun/p/12691476.html