parseZone() function will parse a moment with the offset fixed to the provided offset. Using the same date string:Īs you can see, this time the date has been shifted forward three hours, from 08:33:14 to 11:33:14 to be in line with UTC. When you use the moment UTC constructor, it will convert the date from the offset provided to UTC. If I add six months to this moment, my local offset will be -06:00. It is important to note that the default moment constructor will use information from the browser to keep the moment in the user’s local time, even when offsets change due to DST. As such, if I take my -03:00 date from above, and parse it with moment, I get the following:Īs you can see, the time has been shifted from 08:33:14 to 06:33:14 to reflect the offset change. When you use the default moment constructor, it will convert the date from the provided offset to the environment’s local time.
#I want one moment in time iso
This is a little bit of a complicated statement, but let’s break it down.įirst, the date format causing confusion is usually ISO 8601 format with offset. format() isn’t giving the expected result, it is because the date was parsed with an offset, and the wrong Moment constructor function was used. Ignore the value of _d – it is not useful information. If I had used Moment Timezone, I would also be seeing a wrong value in the console. I parsed a UTC time though, so I’m seeing the wrong result in the console. In most JavaScript implementations, that will cause that object to display in local time. When you dump a Moment object to the console, you see () being called on the _d variable, which is the built-in JavaScript date object that Moment wraps.
#I want one moment in time code
I might run code that looks something like this:Īs you can see, I parsed January 1, but am seeing December 31 in the console. Here are some of the most common reasons why Moment might not be showing what you expect, and the ways to get it to do what you want: The console shows the wrong date when I dump a Moment object I have been answering some Stack Overflow questions lately, and it seems like quite a lot of them all boil down to someone saying that Moment.JS is showing the wrong date.