function getTime(){
var dayArr = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
var myDate = new Date();
var year = myDate.getFullYear();//获取年份并以四位数返回
var month = myDate.getMonth();
var date = myDate.getDate();
var day = myDate.getDay();//获取今天是星期几(将0-6转化为对应的星期格式)
var hour = myDate.getHours();
var minute = myDate.getMinutes();
var second = myDate.getSeconds();
month = (month < 10 ? "0" + month :month);
date = (date < 10 ? "0" + date : date);
day = dayArr[day];
hour = (hour < 10 ? "0" + hour : hour);
minute = (minute < 10 ? "0" + minute : minute);
second = (second < 10 ? "0" + second : second);
document.getElementById("qc_time").innerHTML = year +"年" + month +"月"+ date + "日"
+ " " + day + " " + hour + ":" + minute + ":" + second;
setTimeout("getTime()",1000);
}
onload = getTime();
用js方式获取时间
最新推荐文章于 2024-06-21 09:45:36 发布