Friday, 13 September 2013

Convert time between UTC and specific timezone - New Internationalization API

Convert time between UTC and specific timezone - New Internationalization API

I am trying to use new Internationalization API .I use chrome Version
31.0.1623.0 canary
What I want is
Convert Date Time between UTC and specific time zone (America/New_York in
the example)
To check whether the conversion is Daylight Savings changes aware.
So, is it possible with the current level of support to convert between
these two timezone, when
a. Daylight savings is active
//EDT: 11/2/2013 01:04:05
//UTC: 11/2/2013 05:04:05
b. Not active
//EST: 11/3/2013 01:04:05
//UTC: 11/3/2013 06:04:05
Also why is it December, when I specify month 11 in the below example.
http://jsfiddle.net/kr8FW/2/
console.clear();
var dtf = new Intl.DateTimeFormat('en-US', {timeZone: 'America/New_York'});
//EDT: 11/2/2013 01:04:05
//UTC: 11/2/2013 05:04:05
var utc1 = new Date(Date.UTC(2013, 11, 2, 5, 4, 5))
console.log(dtf.format(utc1));
console.log(utc1.toLocaleString("en-US", {timeZone: "America/New_York"}));
//EST: 11/3/2013 01:04:05
//UTC: 11/3/2013 06:04:05
var utc2 = new Date(Date.UTC(2013, 11, 3, 5, 4, 5))
console.log(utc2.toLocaleString("en-US", {timeZone: "America/New_York"}));
The output was
Console was cleared (index):21
12/2/2013 (index):29
12/2/2013 12:04:05 AM (index):30
12/3/2013 12:04:05 AM

No comments:

Post a Comment