当前时间为:<span id="now"></span>
<script type="text/javascript">
//动态显示年月日时间和周几【凌陈亮(QQ:57404811)】
//显示当前时间的对象ID
gw_now('now')
function gw_now(id){
var obj=window.document.getElementById(id)
var date=new Date()
var year=date.getFullYear()
var month=gw_now_addzero(date.getMonth()+1)
var day=gw_now_addzero(date.getDate())
var hour=gw_now_addzero(date.getHours())
var minute=gw_now_addzero(date.getMinutes())
var second=gw_now_addzero(date.getSeconds())
switch (date.getDay()) {
case 0:week="星期天"break
case 1:week="星期一"break
case 2:week="星期二"break
case 3:week="星期三"break
case 4:week="星期四"break
case 5:week="星期五"break
case 6:week="星期六"break
}
obj.innerHTML=year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second + " " + week
setTimeout("gw_now('" + id + "')",1000)
}
function gw_now_addzero(temp){
if(temp<10) return "0" + temp
else return temp
}
</script>
设置时间格式的时候将小时格式设置为大写HH,例如:YYYY-MM-DD HH:mm:ss==>2018-01-18 20:01:17
小写时为12小时制,例如
YYYY-MM-DD hh:mm:ss==>2018-01-18 08:01:17
<input id="time" type="text"/><input name="kg" type="radio" onclick="t=setInterval(function(){document.getElementById('time').value=new Date().toLocaleTimeString()},1000)"/>开
<input name="kg" type="radio" onclick="clearInterval(t)"/>关