Last active
December 20, 2015 01:39
-
-
Save WenLiangTseng/6050597 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
<script type="text/javascript"> | |
<!-- | |
var d = new Date(); | |
var curr_hour = d.getHours(); | |
var curr_min = d.getMinutes(); | |
document.write(curr_hour + " : " + curr_min); | |
//--> | |
</script> | |
//以下是可以顯示出0的程式碼,例如 22:05 | |
<script type="text/javascript"> | |
<!-- | |
var d = new Date(); | |
var curr_hour = d.getHours(); | |
var curr_min = d.getMinutes(); | |
if (curr_hour < 10) { | |
curr_hour = '0' + curr_hour; | |
} | |
if (curr_min < 10) { | |
curr_min = '0' + curr_min; | |
} | |
document.write(curr_hour + " : " + curr_min); | |
//--> | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment