用数组实现日期计算

1.//创建一个日期对象表示当前时间 2.var objDate=new Date(); 3.var year=objDate.getFullYear(); 4.//getMonth返回的月份是从0开始的,因此要加1 5.var month=objDate.getMonth()+1; 6.var date=objDate.getDate(); 7.var day=objDate.getDay(); 8.var dateMap={"0":"星期日","1":"星期一","2":"星期二","3":"星期三","4":"星期四","5":"星期五","6":"星期六"}; 9.//根据星期数的索引确定其中文表示 10.switch(day) 11.{ 12. case day: 13. day=dateMap[day]; 14. break; 15.} 16.document.write("今天是:"+year+"年"+month+"月"+date+"日  "+day);

你可能感兴趣的:(Date)