Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 589
Mattia Pettenuzzo Avatar asked Mar 30 '17 10:03

Mattia Pettenuzzo


1 Answers

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]')
like image 169
Andrey Avatar answered Sep 29 '22 07:09

Andrey