I am looking for a function to convert date in one timezone to another.
It need two parameters,
- date (in format "2012/04/10 10:10:30 +0000")
- timezone string ("Asia/Jakarta")
The timezone string is described in http://en.wikipedia.org/wiki/Zone.tab
Is there an easy way to do this?
I don't know an easy method to convert a date object to any time zone, but if you want to convert it to the local time zone, you can just convert it with
Date.prototype.getTime()
to the corresponding number of milliseconds, and back again.For example,
date.getHours()
will now return15
instead of13
if you are, like me, in Austria (and it's summer).I've read that the various datetime functions may exhibit non-standard behaviour in some browsers, so test this first. I can confirm that it works in Chrome.
Stolen shamelessly from: http://www.techrepublic.com/article/convert-the-local-time-to-another-time-zone-with-this-javascript/6016329
this function is useful to calculate time zone value by providing name of a city/country and offset value