代码改变世界

JS 时钟 获取当前时间

2013-05-22 23:33  Tellme_C#  阅读(227)  评论(0编辑  收藏  举报

<script type="text/javascript"  language="javascript">
function get_time(){
 
  var date = new Date();
  var year = "",  month = "",  day = "",    hour = "",  minute = "",  second = "";
  year = date.getFullYear();
  month = add_zero(date.getMonth() + 1);
  day = add_zero(date.getDate());
  hour = add_zero(date.getHours());
  minute = add_zero(date.getMinutes());
  second = add_zero(date.getSeconds());
 document.getElementById("time_div").innerHTML="现在时间:" + hour + ":" + minute + ":" + second;
}
function add_zero(temp){
  if(temp < 10) return "0" + temp;
  else return temp;
}
setInterval("get_time()",  1000);
</script>