Rayjax
Rayjax

Reputation: 7784

JavaScript - formatting date with current timezone

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:

Upvotes: 0

Views: 122

Answers (1)

Matt Johnson-Pint
Matt Johnson-Pint

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

Related Questions