0

I am trying to develop an application. Within the application I want to check if the current time falls between time ranges ,what I've completed now that it checks the hour & minute but the Time Set which is the AM/PM is ignored and always gives a wrong result My application let the user set a start time & end time and after clicking "check button" it checks if the current time if it falls within the range , I only need a way to take the factor of AM/PM into consideration so I hope you can give me a hint or something that can help thanks in advance

curhour : current hour

startTimeHour : Hour Start Range

endTimeHour : Hour End Range

same for minutes

 if(curhour>=startTimeHour&&curhour<=endTimeHour)
                     {

                         if(curmin>=startTimeMin&&curmin<=endTimeMin)
                         {
                             Toast.makeText(getApplicationContext(),"Time In Range", Toast.LENGTH_SHORT).show();
                         }


                     }
                     else
                     {
                         Toast.makeText(getApplicationContext(),"Out of Range", Toast.LENGTH_SHORT).show();
                     }
user1928775
  • 355
  • 1
  • 5
  • 15
  • See this near duplicate Question: [See if the current time falls within a specific range of time in the current day in Java](http://stackoverflow.com/q/2473034/642706). Use the [ThreeTenABP](https://github.com/JakeWharton/ThreeTenABP) library for Android. – Basil Bourque Feb 13 '17 at 20:41

1 Answers1

1

The classes contained in the Java API to manipulate time objects are in my opinion hard to use (or at least in realtion to the task they should accomplish). I suggest this excellent library:

Date4j

Alessandro Roaro
  • 4,665
  • 6
  • 29
  • 48