Created
March 15, 2014 09:40
-
-
Save precious-ming/9564112 to your computer and use it in GitHub Desktop.
网页显示当前时间
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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