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 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
本文标签: javascriptWhy does Momentjs day ends at 225959999ZStack Overflow
版权声明:本文标题:javascript - Why does Moment.js day ends at 22:59:59.999Z? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744166163a2593558.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论