<!--javascript取当月最后一天-->
<script language=javascript>
var current = new Date();
var year = current.getYear();
var month = current.getMonth();
showMonthLastDay(year, month);
function showMonthLastDay(year,month)
{
alert("year:"+year+", month:"+month);
year = ( year < 1900 ) ? ( 1900 +year ) : year;
var tempDate = new Date();
tempDate.setYear(year);
tempDate.setMonth(month+1);
tempDate.setDate(0);
var tempYear = tempDate.getYear();
tempYear = ( tempYear < 1900 ) ? ( 1900 +tempYear ) : tempYear;
alert("本月最后一天:"+tempYear+"-"+(tempDate.getMonth()+1)+"-"+tempDate.getDate());
}
</script>
javascript取当月最后一天
最新推荐文章于 2024-05-15 22:33:17 发布
本文介绍了一段JavaScript代码,该代码能够获取并显示当前月份的最后一天。通过设置日期对象来实现跨年的月份切换,并准确获取指定年月的最后一天。
196

被折叠的 条评论
为什么被折叠?



