时间自动刷新

217 阅读1分钟

// 获取当前时间

function getNowDate(){

var date = new Date();

var sep = ".";

var sep2 = ":";

var month = date.getMonth() + 1;

var strDate =date.getDate();

var minutes = date.getMinutes();

// 月
if(month >= 1 && month <=9){

    month = "0" + month;
    
}
if(strDate >= 0 && strDate <=9){//日

    strDate = "0" + strDate;
    
}
if(minutes >=0 && minutes <=9) {

    minutes = "0" + minutes
}

var curDate=date.getFullYear() + sep + month + sep + strDate + " " + date.getHours() + sep2 + minutes;

 // $('#time_1').append(curDate)
 
 //要渲染的div
 
$('#time_1').html(curDate)

}

getNowDate();

// 每间隔1000毫秒让时间更新

setInterval(function () {

getNowDate()

},1000)