我有一个名为 date 的时刻对象:
( Tue Apr 09 2019 00:00:00 ...)
我想在最后一刻将其替换为同一天,如下所示:
(Tue Apr 09 2019 23:59:59 ...)
我尝试使用var date_end = moment().endOf(date)
,
但只有当我输入(日、周或年)时它才有效 是否可以使用 endOf 或者还有其他解决方案?
最佳答案
如果您已经有一个 moment 对象,则只需执行 date.endOf('day')
即可。我认为您误解了文档。
var date = moment('2019-04-09')
console.log('Before endOf', date.format())
date = date.endOf('day')
console.log('after endOf', date.format())
<script src="https://cdn.jsdelivr.net/momentjs/2.14.1/moment-with-locales.min.js"></script>
Mutates the original moment by setting it to the end of a unit of time.
This is the same as moment#startOf, only instead of setting to the start of a unit of time, it sets to the end of a unit of time.
moment().endOf("year"); // set the moment to 12-31 23:59:59.999 this year
关于javascript - Moment() 与预定义的 Moment().endof 日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55688722/