getDay() : 返回星期几,值介于0至6之间
getDate() :返回Date对象中月份的天数,值介于1至30之间
getHours() : 返回Date对象中的小时数,值介于0至23之间
getMinutes() : 返回Date对象中的分钟数,值介于0至59之间
getSeconds() : 返回Date对象中的秒数,值介于0至59之间
getMonth() : 返回Date对象中的月份,值介于0至11之间
getFullYear() : 返回Date对象中的年份,它的值是四位数
getTime() : 返回自谋一时刻(1979年1月1日)以来的毫秒数
ript type="text/javascript">
window.onload=function(){
setInterval(function(){
//获取当前事件
var time = new Date()
console.log(time)
//年份
var year = time.getFullYear()
//月份 0~11 需要加1
var month = time.getMonth()+1
//日
var date = time.getDate()
//小时
var hours = time.getHours()
//分钟
var minutes = time.getMinutes()
//秒数
var seconds = time.getSeconds()
month = month>9?month:"0"+month
date = date>9?date:"0"+date
hours = hours>9?hours:"0"+hours
minutes = minutes>9?minutes:"0"+minutes
seconds = seconds>9?seconds:"0"+seconds
var result = year+"年"+month+"月"+date+"日"+hours+":"+minutes+":"+seconds
document.getElementById("result").innerHTML=result
},1000)
}
</script>