使用moment获取当前月份最后一天的23点59分

获取当前月份最后一天

//1. 先用moment把时间转化为moment时间
let time=moment("Mon Jun 06 2020 00:00:00 GMT+0800 (中国标准时间)")
console.log(time);//Moment {_isAMomentObject: true, _i: "Mon Jun 06 2020 00:00:00 GMT+0800 (中国标准时间)", _isUTC: false, _pf: {…}, _locale: Locale, …}
//2. 使用endOf('')将当前的原始moment时间对象转化为自定义事件单位的末尾 如果用year就是取传入的时间字符串的当年的最后一天
let time=moment("Mon Jun 01 2020 00:00:00 GMT+0800 (中国标准时间)").endOf('month')
console.log(time);
//Moment {_isAMomentObject: true, _i: "Mon Jun 01 2020 00:00:00 GMT+0800 (中国标准时间)", _isUTC: false, _pf: {…}, _locale: Locale, …}
//_d: Tue Jun 30 2020 23:59:59 GMT+0800 (中国标准时间) {}
//_i: "Mon Jun 01 2020 00:00:00 GMT+0800 (中国标准时间)"
//__proto__: Object

//3. 其中_d就是获取到的值 然后再转成时间戳即可
let time=moment("Mon Jun 01 2020 00:00:00 GMT+0800 (中国标准时间)").endOf('month').unix()
console.log(time);//1593532799
posted @ 2020-07-06 18:04  香荣如梦  阅读(2829)  评论(0编辑  收藏  举报