admin管理员组

文章数量:1398166

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 to 23: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
Add a ment  | 

1 Answer 1

Reset to default 6

endOf 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

本文标签: javascriptWhy does Momentjs day ends at 225959999ZStack Overflow