日期:2014-05-16  浏览次数:20364 次

js显示当前时间

<div id="mblog_enter_button" class="mblog_enter_button" style="display: block;padding-left:100px;"></div>
?? ??? ??? ??? ?<script language="javascript" type="text/javascript">
?? ??? ??? ???????? function disptime() {
?? ??? ??? ???????????? var now = new Date(); //创建一个表示当前日期和时间的对象NOW
?? ??? ??? ???????????? var year = now.getFullYear();
?? ??? ??? ???????????? var month = now.getMonth() + 1;
?? ??? ??? ???????????? var date = now.getDate();
?? ??? ??? ???????????? var hours = now.getHours();
?? ??? ??? ???????????? var minutes = now.getMinutes();
?? ??? ??? ???????????? var seconds = now.getSeconds();
?? ??? ??? ???????????? if (month >= 10) { month = month; }
?? ??? ??? ???????????? else { month = "0" + month; }
?? ??? ??? ???????????? if (date >= 10) { date = date; }
?? ??? ??? ???????????? else { date = "0" + date; }
?? ??? ??? ???????????? if (hours >= 10) { hours = hours; }
?? ??? ??? ???????????? else { hours = "0" + hours; }
?? ??? ??? ???????????? if (minutes >= 10) { minutes = minutes; }
?? ??? ??? ???????????? else { minutes = "0" + minutes; }
?? ??? ??? ???????????? if (seconds >= 10) { seconds = seconds; }
?? ??? ??? ???????????? else {seconds = "0" + seconds;}
?? ??? ??? ???????????? document.getElementById("mblog_enter_button").innerHTML = year + "年" + month + "月" + date + "日&nbsp;" + hours + ":" + minutes + ":" + seconds + " ";
?? ??? ??? ???????????? setTimeout("disptime()", 1000)
?? ??? ??? ???????? }?
?? ??? ??? ???????? disptime();
?? ??? ??? ??? ?</script>