欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

获取时间

程序员文章站 2022-05-24 13:22:31
...
<!DOCTYPE html>
<html>
<body>
<div id="txt"></div>
<script>
    function startTimes(){   
        var today=new Date();
        console.log(today);
        var h=today.getHours();
        console.log(h);
        var m=today.getMinutes();
        console.log(m);
        var s=today.getSeconds();
        console.log(s);
        m=checkTime(m);
        s=checkTime(s);
        document.getElementById('txt').innerHTML=h+":"+m+":"+s
        t=setTimeout('startTimes()',500);
    }
    startTimes();
    function checkTime(i) {
        if (i<10) {
            i="0"+i
        }
        return i;
    }
    var date = new Date();
    var weekDay = new Array(7);
        weekDay[0] = "星期日";
        weekDay[1] = "星期一";
        weekDay[2] = "星期二";
        weekDay[3] = "星期三";
        weekDay[4] = "星期四";
        weekDay[5] = "星期五";
        weekDay[6] = "星期六";
        alert(weekDay[date.getDay()]);
</script>

</body>
</html>
相关标签: 获取时间