显示当前日期:年月日时分秒

        var str = "";
        var oDiv = document.getElementsByTagName("div")[0];
        setInterval(function(){
            var date = new Date();
            // 当前日期的年
            var year = date.getFullYear();
            // 当前时间的月
            var month = date.getMonth();
            // 当前时间的日
            var day = date.getDay();
            // 当前时间的时
            var hour = date.getHours();
            // 当前时间的分
            var minutes = date.getMinutes();
            // 当前时间的秒
            var seconds = date.getSeconds();
             str = "当前时间是:" + year + "年"+ month +"月"+ day+"日 " + hour + "时" + minutes + "分" +seconds + "秒";
             oDiv.innerHTML = str;
        },1000);

猜你喜欢

转载自my.oschina.net/korabear/blog/1805233