function getDays() {
//構造當前日期對象
var date = new Date();
//獲取年份
var year = date.getFullYear();
//獲取當前月份
var mouth = date.getMonth() + 1;
//定義當月的天數;
var days;
//當月份為二月時,根據閏年還是非閏年判斷天數
if (mouth == 2) {
days = year % 4 == 0 ? 29 : 28;
}
else if (mouth == 1 || mouth == 3 || mouth == 5 || mouth == 7 || mouth == 8 || mouth == 10 || mouth == 12) {
//月份為:1,3,5,7,8,10,12 時,為大月.則天數為31;
days = 31;
}
else {
//其他月份,天數為:30.
days = 30;
}
return days;
}
歡迎評論。。。。讓我看到你的反饋。。。。
