I'm building on the Actions On Google API using API.ai. In order to fulfil one of my actions I need to know the user's location and local time.
I have been able to successfully ask for and receive back the user's location.
However, I cannot see any way of getting the user's local time or timezone offset. Is there a way to do this?
(I realise that I could use the location to find out the offset but that would require another API call or use of another library, which I'd rather avoid.)
Thanks in advance.
-- Update --
As per Leon's answer below and as of 18th Jan 2017 this info isn't currently provided by the API. In order to get the required info I requested permission for the user's precise location, which returns lat and lng. I then used the GeoNames timezone API to get the timezone offset.
Whilst the timezone isn't included natively yet to my knowledge. You can use location permission alongside libraries to get the local time dynamically.
The libraries I have used here are momentTz and timezone. The latter gets the timezone interpolated from lat/long supplied by location permission. The resolved timezone is then used to convert the standard time in UTC which momentTz provides natively to the local time sought.
const startTz = momentTz(); //Returns standard UTC time, independent of locality
const timestamp = 1402629305; // Any random timestamp will work, it wouldn't unnecessarily impede your results
timezone.data(latitudeValue, longitudeValue, timestamp, function(err, tz) {
if (err) {
console.log(err);
}
var zoneHolder = tz.raw_response.timeZoneId; //Appropriate timezone is returned here based on latitudeValue and longitudeValue passed
const localTime = startTz.tz(zoneHolder).format('LLL'); //local time which you seek;
});
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