Skip to content

Instantly share code, notes, and snippets.

@precious-ming
Created March 15, 2014 09:40
Show Gist options
  • Save precious-ming/9564112 to your computer and use it in GitHub Desktop.
Save precious-ming/9564112 to your computer and use it in GitHub Desktop.
网页显示当前时间
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div>
<span id="nowTime"></span>
</div>
<script type="text/javascript">
var nowTimeSpan=document.getElementById("nowTime");
function showNowTime(){
var nowDate=new Date();
var month=nowDate.getMonth()+1;
if(month<10)
month="0"+month;
var date=nowDate.getDate();
if(date<10)
date="0"+date;
var hour=nowDate.getHours();
if(hour<10)
hour="0"+hour;
var minute=nowDate.getMinutes();
if(minute<10)
minute="0"+minute;
var second=nowDate.getSeconds();
if(second<10)
second="0"+second;
nowTimeSpan.innerText=nowDate.getFullYear()+"-"+
month+"-"+date+" "+hour+":"+minute
+":"+second;
setTimeout(showNowTime,1000);
}
showNowTime();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment