Question

I have a time and date in the "Zulu" time zone (which is the same time zone as Coordinated Universal Time (UTC))

I need to convert this time and date into the Central time zone using jQuery.

Right now Im attempting to use "Moment Timezone" since I already use "Moment" and it seems like Timezone is capable of what I need but the documentation is sparse.

I thought this would work but it returns "Monday, January 20 2014 1:03 AM" without converting the time

var stampString='January 20 2014 01:03';
var m = moment(stampString);
var convertedTime=m.tz("CST6CDT").format('LLLL');

How can I accomplish what I need? Im open to using a different library if needed, possibly an ajax call to some php method? jQuery would be preferred though.

Was it helpful?

Solution

You should not use CST6CDT. That is an old-style POSIX time zone. They're only there for backwards compatibility purposes. The correct zone for US Central Time is America/Chicago. There's a section about POSIX time zones in the timezone tag wiki if you want to learn more.

You'll also need to tell moment exactly what format you are using, and you'll want to tell it that it is being supplied in UTC.

var stampString = 'January 20 2014 01:03';
var m = moment.utc(stampString, "MMMM D YYYY HH:mm");
var convertedTime = m.tz("America/Chicago").format('LLLL');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top