简体   繁体   中英

Google timezone api showing wrong daylight saving offset

So now London is having +1 hour daylight saving. I'm requesting to Google timezone api to request the london timezone. But it's not giving me the right time.

https://maps.googleapis.com/maps/api/timezone/json?location=51.5072,-0.1275&timestamp=1331766000&key=[API_KEY]

This giving me result as

{
   "dstOffset" : 0,
   "rawOffset" : 0,
   "status" : "OK",
   "timeZoneId" : "Europe/London",
   "timeZoneName" : "Greenwich Mean Time"
}

Shouldn't it give me dstOffset of 3600??

I followed this guideline Timezone

What's wrong? How can I get the timezone with the daylight saving on or off?

The timestamp you provided (1331766000) corresponds to 14 Mar 2012 23:00:00 GMT, which probably wasn't a time when daylight saving applied (it starts on the last Sunday in March).

The value should be seconds since 1970-01-01T00:00:00Z, which you can get as Date.now()/1000 since javascript time values are milliseconds since the same epoch. For 2014-06-24T13:15:34.000Z the timestamp is 1403615734. If that is used, you'll get:

{
   "dstOffset" : 3600,
   "rawOffset" : 0,
   "status" : "OK",
   "timeZoneId" : "Europe/London",
   "timeZoneName" : "British Summer Time"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM