Reputation: 7784
I am using the moment.js library. I have dates in this format: "2014-06-19T18:00:00+02:00"
(string). I want to display the date formatted with the user's timezone.
moment.js docs specifies to use moment("2014-06-19T18:00:00+02:00").utc().format()
My questions are:
How can I set the timezone once and not have to put .utc()
every time?
How can I test the timezone functionality? Should I change my computer's clock?
Upvotes: 0
Views: 122
Reputation: 241475
Calling .utc()
would actually translate the value you put in to UTC. If you want the user's local time zone, then you should just omit that and call .format()
.
That you passed a +02:00 offset with the original value doesn't matter. By default, moment will adjust the value to the user's time zone.
On the other hand, if you want to keep the offset you provided, regardless of the user's time zone, then you can use the parseZone
function.
Upvotes: 2