如何在页面刷新时自动打印日期时间

时间:2018-06-16 04:55:36

标签: javascript

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

0 个答案:

没有答案