'Moment.js returning wrong date
I'm trying to use moment to convert Date-Time for October 29th, 2013 with this format
2013-10-29T00:00:00.000Z
However when I do this
moment('2013-10-29T00:00:00.000Z').format("MMM Do, YYYY")
It returns October 28th, 2013 when it should return October 29th, 2013
If you have some ideas on how I can solve this issue, please let me know. Thank you
Solution 1:[1]
If you want the time in utc, use:
moment.utc('2013-10-29T00:00:00.000')
As @MattJohnson pointed out, using the moment constructor will translate it to local time. Instead (if you don't want to use the utc method), you can replace the Z with +0. See options for string date/time http://momentjs.com/docs/#/parsing/string-format/
Solution 2:[2]
You can adjust the timezone settings by doing this:
moment('2013-10-29T00:00:00.000Z').zone(0).format("MMM Do, YYYY");
Going to go ahead and add Matt's suggestion as well, since it is more semantic.
moment('2013-10-29T00:00:00.000Z').utc().format("MMM Do, YYYY");
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 |
