本文实例讲述了js实现获取当前时间是本月第几周的方法。分享给大家供大家参考。具体如下:
<script language="javascript">var getMonthWeek = function (a, b, c) { var date = new Date(a, parseInt(b) - 1, c), w = date.getDay(), d = date.getDate(); return Math.ceil( (d + 6 - w) / 7 ); };var getYearWeek = function (a, b, c) { var date1 = new Date(a, parseInt(b) - 1, c), date2 = new Date(a, 0, 1), d = Math.round((date1.valueOf() - date2.valueOf()) / 86400000); return Math.ceil( (d + ((date2.getDay() + 1) - 1)) / 7 ); }; today=new Date();//获取当前时间var y = today.getYear();var m = today.getMonth()+1;var d = today.getDate();document.write( "今天是",m,"月的第 ", getMonthWeek(y, m, d), " 周" ); </script>希望本文所述对大家的javascript程序设计有所帮助。