AtanuCSE
AtanuCSE

Reputation: 8940

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?

Upvotes: 1

Views: 1739

Answers (1)

RobG
RobG

Reputation: 147403

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"
}

Upvotes: 3

Related Questions