In my application some functionality get closed after 9:00 PM. Its working fine if date setting of device is auto updated. But suppose right now its 10:00 pm and user changed the time 10:00 Pm to 08:00 Pm then my code is working. I want to avoid that thing.
Asked
Active
Viewed 1,846 times
2 Answers
0
Get the system time in UTC (Universal Coordinate Time). This answer gives it in more detail
DateFormat df = DateFormat.getTimeInstance();
df.setTimeZone(TimeZone.getTimeZone("gmt"));
Calendar cal = df.getCalendar();
int hour = cal.get(Calendar.HOUR_OF_DAY);
if (hour > 21 && hour < 9) // or 9:00pm in your time-zone converted to gmt...
{
// Do something, or don't do something
}