bsr
bsr

Reputation: 58742

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

  1. Convert Date Time between UTC and specific time zone (America/New_York in the example)
  2. 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 

Upvotes: 0

Views: 1487

Answers (1)

Lee Meador
Lee Meador

Reputation: 12985

The javascript Date says the months are 0-11.

Daylight savings ends at 2 AM on 3 Nov 2013. So both times are within daylight savings in US Eastern time zone.

Upvotes: 1

Related Questions