function displayTime()
{
var localTime = new Date();
var year= localTime.getFullYear();
var month= localTime.getMonth() +1;
var date = localTime.getDate();
var hours = localTime .getHours();
var minutes = localTime .getMinutes();
var seconds = localTime .getSeconds();
var div=document.getElementById("div1");
div.innerText=year+"-"+month+"-"+date+" "+hours+":"+minutes+":"+seconds;
}
HTML:
我希望输出如上所述:2018-6-15 17:50:46
目前刷新:2018-6-15 18:50:46