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?
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?
- 3 are you in a timezone that is UTC+1 perhaps – Jaromanda X Commented Mar 30, 2017 at 10:50
- Yes, but it does matter? – Mattia Pettenuzzo Commented Mar 30, 2017 at 10:51
-
for me your code returns
06h 30min 00sec
– Pranav Patel Commented Mar 30, 2017 at 10:51 - 1 so, the +1 hour of your timezone isn't a clue as to what is going on? ... – Jaromanda X Commented Mar 30, 2017 at 10:51
- I've tried and it's the timezone that matters – Mattia Pettenuzzo Commented Mar 30, 2017 at 10:53
1 Answer
Reset to default 8Moment 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]')