How to compare current time with time range?

前端 未结 8 1749
庸人自扰
庸人自扰 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:24

    As of now, I am thinking about the following approach:

    int clTime = Integer.parseInt(time1.substring(0, 1))*60 + Integer.parseInt(time1.substring(3, 4)); 
    
    Time now = new Time();
    now.setToNow();
    int nowTime = now.hour*60 + now.minute;
    

    So, I'll need to compare just integer values clTime and nowTime.

提交回复
热议问题