setInterval() 方法可按照指定的周期(以毫秒计)来调用函数或计算表达式

时间:2023-01-14 14:33:38
 <script type="text/javascript">
setInterval(function(){
var myDate = new Date();
var $_year = myDate.getFullYear();
var $_month = parseInt(myDate.getMonth())+1;
var $_day = myDate.getDate(); var $_hour = myDate.getHours();
var $_minute = myDate.getMinutes();
var $_second = myDate.getSeconds(); if ($_hour < 10) {
$_hour = "0" + $_hour;
}
if ($_minute < 10) {
$_minute = "0" + $_minute;
}
if ($_second < 10) {
$_second = "0" + $_second;
} var $_f_date2 = $_year +"年"+$_month+"月"+$_day+"日"+" "+$_hour+":"+$_minute+":"+$_second;
time.innerHTML = $_f_date2;
},1000) //每过1秒运行一次
</script>