Javascript获取日期和星期

javascript获取日期,亮点:方法ie跟其他浏览器不同。

function getDateWeek()
{
todayDate = new Date();
date = todayDate.getDate();
month= todayDate.getMonth() +1;
year= todayDate.getYear();
var dateweek = "今天是:";
if(navigator.appName == "Netscape")
{
    dateweek = dateweek + (1900+year) + "年" + month + "月" + date + "日 ";
}
if(navigator.appVersion.indexOf("MSIE") != -1)
{
    dateweek = dateweek + year + "年" + month + "月" + date + "日 ";
}
switch(todayDate.getDay())
{
case 0:dateweek += "星期日";break;
case 1:dateweek += "星期一";break;
case 2:dateweek += "星期二";break;
case 3:dateweek += "星期三";break;
case 4:dateweek += "星期四";break;
case 5:dateweek += "星期五";break;
case 6:dateweek += "星期六";break;
}
return dateweek;
}

转自:http://mlgy.i.sohu.com/blog/view/141540690.htm

posted on 2013-01-04 17:19  靖儿  阅读(310)  评论(0编辑  收藏  举报

导航