45fan.com - 路饭网

搜索: 您的位置主页 > 网络频道 > 阅读资讯:如何通过JavaScript获取一个月的最后一天?

如何通过JavaScript获取一个月的最后一天?

2016-09-04 22:07:39 来源:www.45fan.com 【

如何通过JavaScript获取一个月的最后一天?

<script language=javascript>
function leapYear(year)
{

if (year % 4 == 0) // basic rule

return true; // is leap year

/* else */ // else not needed when statement is "return"

return false; // is not leap year

}

function getDays(month, year)
{

// create array to hold number of days in each month

var ar = new Array(12);

ar[0] = 31; // January

ar[1] = (leapYear(year)) ? 29 : 28; // February

ar[2] = 31; // March

ar[3] = 30; // April

ar[4] = 31; // May

ar[5] = 30; // June

ar[6] = 31; // July

ar[7] = 31; // August

ar[8] = 30; // September

ar[9] = 31; // October

ar[10] = 30; // November

ar[11] = 31; // December

// return number of days in the specified month (parameter)

return ar[month];

}
alert(getDays(8-1,2006));

</script>

 

本文地址:http://www.45fan.com/a/question/72409.html
Tags: 获取 JavaScript 一个月
编辑:路饭网
关于我们 | 联系我们 | 友情链接 | 网站地图 | Sitemap | App | 返回顶部