js获取当前日期和星期

var myDate = new Date();
myDate.getDay(); //获取当前星期X(0-6,0代表星期天)
myDate.toLocaleDateString();
var days = myDate.getDay();
if(days=='5'){
days = "五";
}else if(days=='4'){
days = "四";
}else if(days=='3'){
days = "三";
}else if(days=='2'){
days = "二";
}else if(days=='1'){
days = "一";
}else if(days=='6'){
days = "六";
}else{
days = "日"
}

document.write("北京时间:"+myDate.toLocaleDateString().replace(///g,".")+" 周"+days);

标签: none

评论已关闭