How to compare current time with time range?

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

    if you want time between after 9PM to before 9Am you can use following condition..

    if(cal.get(Calendar.HOUR_OF_DAY)> 20 || cal.get(Calendar.HOUR_OF_DAY)< 9)
    {
        // do your stuffs
    }
    

提交回复
热议问题