- 判斷當(dāng)前日期是不是當(dāng)前年月的最后一天
function isLastDay(inputDate) {
var d = new Date(inputDate.replace(/\-/, "/ "));
var nd = new Date(d.getTime() + 24 * 60 * 60 * 1000); //next day
return d.getMonth() != nd.getMonth();
}
cosole.log("isLastDay",isLastDay("2000-02-29")); // true
cosole.log("isLastDay",isLastDay("2001-02-29")); // false
- 獲取月份的最后一天
// 系統(tǒng)時(shí)間格式
console.log(new Date('2018','05',0)) // Thu May 31 2018 00:00:00 GMT+0800 (中國(guó)標(biāo)準(zhǔn)時(shí)間)
// 取出數(shù)字
console.log(new Date('2021','02',0).getDate()) // 28
console.log(new Date('2020','02',0).getDate()) // 29
- 數(shù)組中日期排序
來(lái)源于:https://www.cnblogs.com/matthew9298-Begin20160224/p/5433977.html
// 原數(shù)組
var timeArr=[
{'id':'A01','date':'2016-04-20 23:22:11'},
{'id':'A02','date':'2016-04-21 21:00:11'},
{'id':'A03','date':'2016-04-23 22:00:22'},
{'id':'A04','date':'2016-04-19 12:22:00'},
{'id':'A05','date':'2016-02-19 11:11:00'}
];
timeArr.sort(function(a,b) {return Date.parse(b.date.replace(/-/g,"/"))-Date.parse(a.date.replace(/-/g,"/"));});
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。