如何使用JavaScript获取指定月份的天数?
要获取一个月中的天数,请使用getDate()方法并获取天数。
示例
您可以尝试运行以下代码以获取一个月中的天数-
<!DOCTYPE html>
<html>
<body>
<script>
var days = function(month,year) {
return new Date(year, month, 0).getDate();
};
document.write("Days in July: "+days(7, 2012)); // July month
document.write("<br>Days in September: "+days(9, 2012)); // September Month
</script>
</body>
</html>输出结果
Days in July: 31 Days in September: 30
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短