0

Is there a way to get today's date and time such that it corresponds to the real world date/time and is not affected if the user has changed the date/time settings on their phone/web browser?

If not, is using a server time the best way to correctly determine today's date on the phone? Or are there other best practices?

Pratik Mandrekar
  • 9,362
  • 4
  • 45
  • 65

3 Answers3

0

if you don't want to use a server time, u can parse the return of gettime() link

Izu
  • 235
  • 1
  • 5
0

Server time suits most of the needs. Then if your server's time is messed up then you will be in problem.

Alternatively, you can use some third party web service to provide you with the time. For example https://developers.google.com/maps/documentation/timezone/

Google being a reputed company, the time returned can be trusted to be correct.

Hirak
  • 3,601
  • 1
  • 22
  • 33
0

I'd never trust a user's device to retrieve time related information. Get the UTC time from the server and if required, display it to the user converted to his time zone. Here's a so question on how to convert UTC time to local time with JS

This way your stored time will always be ok and in same "format". The only thing that could happen is that the ends up seeing a "wrong" time, if he faked his location / time zone settings. But I wouldn't mind that.

Community
  • 1
  • 1
Robin Drexler
  • 4,307
  • 3
  • 25
  • 28