How to compare current time with time range?

前端 未结 8 1744
庸人自扰
庸人自扰 2020-12-30 12:02

I have two String variables - time1 and time2. Both contain value in the format HH:MM. How can I check:

  1. If the current time
8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-30 12:26

    SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm");
    
    Date EndTime = dateFormat.parse("10:00");
    
    Date CurrentTime = dateFormat.parse(dateFormat.format(new Date()));
    
    if (CurrentTime.after(EndTime))
    {
        System.out.println("timeeee end ");
    }
    

    Don't forget to surrounded with a try catch block

提交回复
热议问题