moment.format() returning incorrect hours

Created on 23 Feb 2017  ·  5Comments  ·  Source: moment/moment

Description of the Issue and Steps to Reproduce:
I have found an issue with moment.format() function returning incorrect string as follow:
pasted image at 2017_02_24 11_22 am

Above test were conducted on https://momentjs.com/ with Chrome console.

Experiencing same issue with our application. (Node 6.2.2)

Environment:

Chrome 56.0.2924.87 on OSX, moment 2.15.1

image

Most helpful comment

I'm going to assume you mean incorrect minutes, not hours. The reason you are seeing that is that you are using MM which is the token for months. You want mm.

All 5 comments

I'm going to assume you mean incorrect minutes, not hours. The reason you are seeing that is that you are using MM which is the token for months. You want mm.

Oh, you have quite a few things going on here.

First, you're using 24 hour clock instead of 12 with the HH token. You probably want hh:mm a for your tokens.

Second, you have a UTC date, and it is converting to local. To keep it utc, use moment.utc() instead of moment(). See this blog post: https://maggiepint.com/2016/05/14/moment-js-shows-the-wrong-date/

Oh rights, thanks for detailed feedback.
hh:mm a did resolve the issue.

Oh, you have quite a few things going on here.

First, you're using 24 hour clock instead of 12 with the HH token. You probably want hh:mm a for your tokens.

Second, you have a UTC date, and it is converting to local. To keep it utc, use moment.utc() instead of moment(). See this blog post: https://maggiepint.com/2016/05/14/moment-js-shows-the-wrong-date/

@maggiepint .utc resolved my issue :)

Oh, you have quite a few things going on here.
First, you're using 24 hour clock instead of 12 with the HH token. You probably want hh:mm a for your tokens.
Second, you have a UTC date, and it is converting to local. To keep it utc, use moment.utc() instead of moment(). See this blog post: https://maggiepint.com/2016/05/14/moment-js-shows-the-wrong-date/

@maggiepint .utc resolved my issue :)

Even mine thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

IbraheemAlSaady picture IbraheemAlSaady  ·  3Comments

BCup picture BCup  ·  3Comments

vbullinger picture vbullinger  ·  3Comments

tanepiper picture tanepiper  ·  3Comments

danieljsinclair picture danieljsinclair  ·  3Comments