Skip to content

Instantly share code, notes, and snippets.

@WenLiangTseng
Last active December 20, 2015 01:39
Show Gist options
  • Save WenLiangTseng/6050597 to your computer and use it in GitHub Desktop.
Save WenLiangTseng/6050597 to your computer and use it in GitHub Desktop.
JavaScript顯示目前系統時間
<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