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
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/
You can adjust the timezone settings by doing this:
moment('2013-10-29T00:00:00.000Z').zone(0).format("MMM Do, YYYY");
FIDDLE
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");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With