将日期转换为指定的格式:比如转换成 年月日时分秒 这种格式
setInterval(function(){
var d = new Date()
var year = d.getFullYear()
var month = d.getMonth() + 1
var day = d.getDate()
var hour = d.getHours()
var min = a(d.getMinutes())
var sec = a(d.getSeconds())
var week = d.getDay()
var arr = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]
function a(m){
if(m < 10){
return "0" + m
}else return m
}
//当分和秒小于0时,自动补0
box.innerHTML = year + "年" + month + "月" + day + "日" + " " + hour + ":" + min + ":" + sec + " " + arr[week]
},1000)