格式化输出时间
// 格式化输出时间
// 1创建当前的时间对象
var time = new Date()
// 2根据当前的事件对象获取对应的年月日时分秒
var year = time.getFullYear()
var month = time.getMonth() + 1
var day = time.getDay()
var hour = time.getHours()
var minite = time.getMinutes()
var seconds = time.getSeconds()
// 3给小于10的月份,日期,小时,分钟\秒数补0
month = addZero(month)
day = addZero(day)
hour = addZero(hour)
minite = addZero(minite)
seconds = addZero(seconds)
// 4拼接格式化的字符串
var str = year + '-' + month + '-' + day + ' ' + hour + ':' + minite + ':' + seconds
document.write(str)
function addZero(t) {
return t>9? t : '0'+t
}