Javascript 獲取某個月的總天數

由於JavaScript中day的範圍爲1~31中的值,所以當設爲0時,會向前 一天,也即表示上個月的最後一天。

var date = new Date();
var year = date.getFullYear();
var Month = date.getMonth()+1;
var tempDate = new Date(year,Month,0);
var lastMonthday = tempDate.getDate();
console.log('lastMonthday: ' + lastMonthday);

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章