Mattia Pettenuzzo
Mattia Pettenuzzo

Reputation: 195

Why moment is adding one hour?

When I use:

console.log(moment(1000*60*60*1).format('hh[h] mm[min] ss[sec]'));

I get 2h 0min 0sec instead of just 1hour.
I made a workaround by adding .subtract(1, 'hour') like this:

console.log(moment(1000*60*60*1).subtract(1, 'hour').format('hh[h] mm[min] ss[sec]'));

I'm still learning this library that i found today. Am I missing something?
What am I supposed to do if I have milliseconds and I want to get a formatted date out of it?

Upvotes: 6

Views: 6452

Answers (1)

Andrey
Andrey

Reputation: 4050

Moment counts your timezone, to get the time without timezone offset you can use

moment(1000*60*60*1).utc().format('hh[h] mm[min] ss[sec]')

Or

moment.utc(1000*60*60*1).format('hh[h] mm[min] ss[sec]')

Upvotes: 8

Related Questions