< script language = "javascript" > var getMonthWeek = function(a, b, c)
{ /* a = d = 當前日期 b = 6 - w = 當前周的還有幾天過完(不算今天) a + b 的和在除以7 就是當天是當前月份的第幾周 */ 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)
{ /* date1是當前日期 date2是當年第一天 d是當前日期是今年第多少天 用d + 當前年的第一天的周差距的和在除以7就是本年第幾周 */ 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.getFullYear(); var m = today.getMonth() + 1; var d = today.getDate(); document.write("今天是"+ m + "月的第 " + getMonthWeek(y, m, d) + " 周"); document.write("<br /><br />"+today.getHours()+":"+ today.getMinutes()+":"+ today.getSeconds()); < /script>
但願本文所述對你們的javascript程序設計有所幫助。javascript