0

In android I use this code to get the current date:

String phone_date = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(new Date());

It will display 2019-03-05 Asia Time Basis.

If I go to settings of my phone and change it to 2019-03-04, the code above will give me the same.

How can I check if the date is today? I found solutions that mostly requires net but my app is offline.

Is there any way to check it, like compare it to phones internal date?

marchoy
  • 117
  • 1
  • 8
Nardong Bagsik
  • 218
  • 6
  • 20
  • 1
    I think you need to check it online to guarantee time is correct – pb772 Mar 05 '19 at 00:59
  • Your in a locked room with nothing in the room (no windows, no phone signal, no WIFI, no GPS) except a phone. The phone may have been messed with by a hacker and it might not be the right date for your location. By what means do you find the the correct date ? This is essentially what you have asked. – Jon Goodwin Mar 05 '19 at 01:04
  • @JonGoodwin basically ur right :( – Nardong Bagsik Mar 05 '19 at 01:05
  • but gps will not be on also :( – Nardong Bagsik Mar 05 '19 at 01:28
  • I think there is no option if you are offline and not rely on system date. – Farid Haq Mar 05 '19 at 02:02
  • You could keep your own clock time in a foreground service, so you could ignore tampering by a hacker of the system clock, but if you reboot your phone, your are back where you started. The only option is to blow the bloody doors off... ;O) – Jon Goodwin Mar 05 '19 at 02:09
  • maybe i will just keep this post here maybe in future someone will answer it. thnx for telling the truth even if it hurts :( – Nardong Bagsik Mar 05 '19 at 02:28
  • Your app is offline, but the time is really required by your app? if yes, then why not just check if the Date and Time is Automatically set or not. – dotGitignore Mar 05 '19 at 02:42
  • @dotGitignore time is not required on my app just only the date – Nardong Bagsik Mar 05 '19 at 03:01

0 Answers0