I'm working on an app that it using Google API for maps, but the problem I am having is obtaining correct local time. I can not use JS, because a user can travel to a different location and probably won't change the time settings. Also the server seems to be somewhat off and I have no control over its UNIX time. However, anytime you google for local time, you get based on your location. Since my app is using location as well, shouldn't I be able to access that time as well?
This can be done using Google Timezone API:
1- First use Google Timezone API to obtain the user's time zone info, the api accepts the target time (timestamp) in UTC (as UNIX time in secs) and location data
2- The response contains three important fields:
Using the first two you can get your date in JS as:
var localDate = new Date((timestamp + dstOffset + rawOffset) * 1000);
or by third one using timezone-js or moment-timezone.
Have a look at this answer for using timezone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With