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?
Most desktop (not mobile) browsers except Safari support the toLocaleString function with arguments, older browsers usually ignore the arguments.
You can try this also for convert date timezone to India:
there is an npm module called 'timezones.json' you can use for this; it basically consists of a json file with objects containing information on daylight savings and offset,....
for asia/jakarta it would be able to return this object:
you can find it here:
https://github.com/dmfilipenko/timezones.json
https://www.npmjs.com/package/timezones.json
hope it's useful
I recently did this in Typescript :
I Use "en-UK" format because it is a simple one. Could have been "en-US" or whatever works.
If first argument is your locale timezone and seconde is your target timezone it returns a Date object with the correct offset.
You can use to toLocaleString() method for setting the timezone.
For India you can use "Indian/Christmas" and the following are the various timeZones,
Set a variable with year, month, and day separated with '-' symbols, plus a 'T' and the time in HH:mm:ss pattern, followed by +01:00 at the end of the string (in my case the time zone is +1). Then use this string as the argument for the date constructor.