문제

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.

도움이 되었습니까?

해결책

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');
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top