【javascript】显示当前系统详细时间

js实现

    setInterval(function (){
        var date = new Date();
        var now = "现在时间是: ";

        now += date.getFullYear() + " 年 ";
        now += (date.getMonth()+1)+ " 月 ";
        now += date.getDate()     + " 日 ";
        now += date.getHours()    + " 时 ";
        now += date.getMinutes()  + " 分 ";
        now += date.getSeconds()  + " 秒 ";

        var week = new Array("日", "一", "二", "三", "四", "五", "六");

        var weekIndex = date.getDay();

        now += " 星期" + week[weekIndex];

        $("#time").html(now);
    }, 1000);

html代码

结果截图

显示时间样式

你可能感兴趣的:(【javascript】显示当前系统详细时间)