Created
May 25, 2013 17:52
-
-
Save SFantasy/5650053 to your computer and use it in GitHub Desktop.
JavaScript实时获取时间
This file contains 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> | |
<head> | |
<meta charset="utf-8"> | |
<title>Clock</title> | |
<script> | |
var i; | |
function getTime () { | |
var date = new Date(); | |
var year = date.getFullYear(); | |
var month = date.getMonth(); | |
var day = date.getDay(); | |
var hour = date.getHours(); | |
var minute = date.getMinutes(); | |
var seconds = date.getSeconds(); | |
var time = ""; | |
time += year + "年-"; | |
time += month + "月-"; | |
time += day + "日 " | |
time += hour + "点 "; | |
time += minute + "分 "; | |
time += seconds + "秒"; | |
document.getElementById('showtime').value = time; | |
i = setTimeout('getTime()', 1); | |
} | |
</script> | |
</head> | |
<body onload="getTime()"> | |
<input id="showtime" type="text" size="100"> | |
<button onclick="getTime()">Get Time!</button> | |
<button onclick="clearTimeout(i)">Stop!</button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment