moment 时间转换

console.log(moment().startOf('day').unix());//今天 00:00
console.log(moment().endOf('day').unix() + '\n');
//明天后天和昨天前天直接加上86400即可 一天的时间是86400秒
let tmp = Date.parse(new Date()).toString();
let tmp2 = parseInt(tmp.substr(0, 10));//今天
console.log(tmp2,'今天'+'\n');
//86400000
//上周第一天
console.log(moment().week(moment().week() - 1).startOf('week').unix());
//上周最后一天
console.log(moment().week(moment().week() - 1).endOf('week').unix() + '\n');

//本周第一天
console.log(moment().week(moment().week()).startOf('week').unix(),'本周第一天');
//本周最后一天
console.log(moment().week(moment().week()).endOf('week').unix() + '\n');

//下周第一天
console.log(moment().week(moment().week() + 1).startOf('week').unix());
//下周最后一天
console.log(moment().week(moment().week() + 1).endOf('week').unix() + '\n');

//上个月第一天
console.log(moment().month(moment().month() - 1).startOf('month').unix());
//上个月最后一天
console.log(moment().month(moment().month() - 1).endOf('month').unix() + '\n');

//本月第一天
console.log(moment().month(moment().month()).startOf('month').unix());
//本月最后一天
console.log(moment().month(moment().month()).endOf('month').unix() + '\n');

//下个月第一天
console.log(moment().month(moment().month() + 1).startOf('month').unix(),'下个月');
//下个月最后一天
console.log(moment().month(moment().month() + 1).endOf('month').unix() + '\n');
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容