显示当前年月日星期
<script>
function show_times() {
var date_obj=new Date();
var year=date_obj.getFullYear();
var month=date_obj.getMonth()+1; //月会差一个月所以加1
var day=date_obj.getDate();
var hour=date_obj.getHours();
var minutes=date_obj.getMinutes();
var second=date_obj.getSeconds();
var xq=date_obj.getDay();
if (xq==0){xq="日"}
else if(xq==1){xq="一"}
else if(xq==2){xq="二"}
else if(xq==3){xq="三"}
else if(xq==4){xq="四"}
else if(xq==5){xq="五"}
else {xq="六"}
return year+"年"+month+"月"+day+"日"+"\xa0\xa0\xa0\xa0\xa0"+hour+":"+minutes+":"+second+"星期"+xq; // \xa0是空格
}
document.write(show_times())
</script>
关于星期和日期还可以写的NB一点
<script>
function show_times() {
var date_obj=new Date();
var year=date_obj.getFullYear();
var month=date_obj.getMonth()+1;
var day=date_obj.getDate();
var hour=date_obj.getHours();
var minutes=date_obj.getMinutes();
var second=date_obj.getSeconds();
var xq=date_obj.getDay();
return year+"年"+buling(month)+"月"+buling(day)+"日"+"\xa0\xa0\xa0\xa0\xa0"+hour+":"+buling(minutes)+":"+buling(second)+numToWeek(xq);
}
function numToWeek(n){
var week=["星期日","星期一","星期二","星期三","星期四","星期五","星期六",]
return week[n]
}
function buling(num){
if(num>=10){return num;}
else {return "0"+num;}
}
document.write(show_times())
</script>
取时间是get设置是set