mikephilipp
mikephilipp

Reputation: 63

momentJS-timezone always displays UTC time

I am having trouble getting time(HH:mm) from different timezone. Tried it with the moment-timezone doc and searched stackoverflow.

I even found a working jquery fiddle:

http://jsfiddle.net/uq99udc9/4/

(actually wanted to not use jquery, but gave it a try) Literally copy/pasted the fiddle in my project and in an empty JS file. But "Thailand date time" and "America date time" always show "moment.js utc local timezone UTC". So right now it displays 07:00pm (UTC time at the moment) on both Thailand AND America...

What am I doing wrong?

Of course tried the docs example as well

var a = moment.tz("2013-11-18 11:55", "America/Toronto");
var b = moment.tz("May 12th 2014 8PM", "MMM Do YYYY hA", "America/Toronto");
var c = moment.tz(1403454068850, "America/Toronto");
a.format(); // 2013-11-18T11:55:00-05:00
b.format(); // 2014-05-12T20:00:00-04:00
c.format(); // 2014-06-22T12:21:08-04:00

I am just not getting it, I think. What time/date would you pass in the first argument before "America/Toronto" for instance?

Upvotes: 2

Views: 886

Answers (1)

mikephilipp
mikephilipp

Reputation: 63

Maybe someone can give me a working example? Because I am just not getting along with the docs, when even the jsfiddle didnt work.

UPDATE: I worked it out!! The problem was, that i was importing/including moment.js, moment-timezone.js, moment-timezone-with-data-2010-2020.js.

But in fact: I only have to import moment,js and moment-timezone-with-data-2010-2020.js... As soon as I deleted moment-timezone.js, everything was working fine. Cheers!

Upvotes: 1

Related Questions