js获取当前时间

function today()
{
    var date = new Date();
    var day = date.getDay();
    if(day == 0)
    {
        day = "日";
    }
    var today = "现在是:" + (date.getFullYear()) + "年" + (date.getMonth() + 1) + "月" + date.getDate() + "日" + "星期" + day + " " +  date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
    document.getElementById("today").innerHTML = today;
}

代码片段

<body onload="today();">
    
    <font id="today"></font>
<bady>

 

posted on 2014-04-23 22:15  端着咖啡码农  阅读(271)  评论(0编辑  收藏  举报