<script>
function getMonthWeek (a, b, c) {
var date = new Date(a, parseInt(b) - 1, c), w = date.getDay(), d = date.getDate();
return Math.ceil((d+7-w)/7);
};
var last=new Date(2013,9, 0);//获取当前月最后一天时间
var y = last.getFullYear();
var m = last.getMonth()+1;
var d = last.getDate();
document.write( "周数"+ getMonthWeek(y, m, d)+' 年 ' +y+ ' 月 '+m+' 日 ' + d );
</script>
本文介绍了一个使用JavaScript编写的简单函数,该函数可以计算指定日期所在月份的总周数。通过获取月份的最后一天,利用Date对象计算出这一天是该月的第几周。

5045

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



