1

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.

Pavya
  • 6,015
  • 4
  • 29
  • 42

2 Answers2

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
}
Community
  • 1
  • 1
hack_on
  • 2,532
  • 4
  • 26
  • 30
0

you have to use the external time service like this one. anything else like System.currentTimeMillis() or new Date() can be "hacked" by user

injecteer
  • 20,038
  • 4
  • 45
  • 89