When using Moment.js to get the end of a day, it returns 22:59:59.999Z:
moment('2013-W06-5').endOf('day') // 2013-02-08T22:59:59.999Z
See .
Can anyone please explain why the day doesn't end at 23:59:59.999Z?
I don't think Moment.js handles it wrong. Maybe it's something about daylight saving time (writing from German)?
When using Moment.js to get the end of a day, it returns 22:59:59.999Z:
moment('2013-W06-5').endOf('day') // 2013-02-08T22:59:59.999Z
See http://plnkr.co/edit/nS6o5F.
Can anyone please explain why the day doesn't end at 23:59:59.999Z?
I don't think Moment.js handles it wrong. Maybe it's something about daylight saving time (writing from German)?
Share Improve this question edited Jun 1, 2017 at 15:00 Sommereder asked Jun 1, 2017 at 8:28 SommerederSommereder 9244 gold badges12 silver badges32 bronze badges 3-
From the docs,
endOf
set the moment to23:59:59.999
, I don't think it is a bug, probably something in your code, you need to share it to let us help you further. – VincenzoC Commented Jun 1, 2017 at 13:58 - I don't think its a bug either. Added source code and link to Plunker to original post. – Sommereder Commented Jun 1, 2017 at 15:00
-
The issue is the way you are showing the value inside your angular view. Convert moment object to string using
format()
in your controller or use angular-moment inside your view. – VincenzoC Commented Jun 1, 2017 at 15:05
1 Answer
Reset to default 6endOf is timezone aware.
Use .utc() and you get what you need:
$scope.output = moment('2013-W06-5').utc().endOf('day');
=> "2013-02-08T23:59:59.999Z"
http://plnkr.co/edit/BgcBpRmldQL7po4W4vFv?p=preview