开发者

Webservice to convert timzezone name to GMT Offset

开发者 https://www.devze.com 2023-01-30 13:21 出处:网络
Does anyone know a webservice that converts a timezone string to the corresponding GMT Offset? Meaning I like to send a HTTP request like this:

Does anyone know a webservice that converts a timezone string to the corresponding GMT Offset?

Meaning I like to send a HTTP request like this:

http://servcer.com/getgmtoffset?timezone=Europe/Zurich

and get "+1" returned.

Why external service?

I'm writing a google apps script, where the API does not have such conversion options and I prefer not to update the conversion table myself, when countries decide to use different daylight 开发者_运维技巧saving time parameters.


I see you already have a solution, but I wanted to point out that the timezone offset is meaningless without a specific date within that timezone. The offset will change in many timezones throughout the year to account for daylight savings time.

It appears you only need to know the offset at the specific time you make the API call. If you need it for any arbitrary date, you'll need to pass the date and timezone to an API to get the correct offset.

There are some great Timezone Geocoding APIs available here that you might find useful: Timezone lookup from latitude longitude


I found something in this answer

http://json-time.appspot.com/time.json?tz=Europe/Zurich

{
  "tz": "Europe\/Zurich", 
  "hour": 9, 
  "datetime": "Thu, 16 Dec 2010 09:29:16 +0100", 
  "second": 16, 
  "error": false, 
  "minute": 29
}


I don't think there is a web service for that. Probably because countries rarely (never?) change their daylight savings time policy.

I don't know what you can do in google apps scripts, but if you have access to the Java libraries you could just use the TimeZone.getOffset(long) method.

You might also try this, but it might be hacking since you'll probably need to parse the html response ...

0

精彩评论

暂无评论...
验证码 换一张
取 消