使用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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM