[英]Mapping month to the number of the last day of that month
考虑到2月leap年的最后一天是28,我如何将月份数字映射到该月最后一天的数字,否则是29
Sure, you can get the last day of the month like this: 当然,您可以这样获取月份的最后一天:
var month = 1; // Feb var date = new Date((new Date()).getYear(), month + 1, 0); alert("Last day of the month is: " + date.getDate());
Here it is as a function: 这是一个函数:
function getLastDayOfMonth(month) {
return (new Date((new Date()).getYear(), month + 1, 0)).getDate();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.