Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moment.format() returning incorrect hours #3785

Closed
hcho112 opened this issue Feb 23, 2017 · 8 comments
Closed

moment.format() returning incorrect hours #3785

hcho112 opened this issue Feb 23, 2017 · 8 comments

Comments

@hcho112
Copy link

hcho112 commented Feb 23, 2017

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

@maggiepint
Copy link
Member

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.

@maggiepint
Copy link
Member

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/

@hcho112
Copy link
Author

hcho112 commented Feb 24, 2017

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

@alpharameeztech
Copy link

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 :)

@Nani2777
Copy link

Nani2777 commented Nov 5, 2020

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

@theforcee
Copy link

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.

holy s. unbelievable. thank a lot

@Nani2777
Copy link

Nani2777 commented Dec 3, 2021 via email

@patrickcavli
Copy link

Thanks for this issue. This specific issue encourages and teaches us to properly read the documentation, before implementing or integrating any sort of libraries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants