使用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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值