时钟特效

// 时钟特效-----------------


                        

function startTime() {
    var today = new Date()
    // console.log(today)
    var h = today.getHours()
    var m = today.getMinutes()
    var s = today.getSeconds()
    var d = today.getDate()
    var mon = today.getMonth()+1
    var y = today.getFullYear()
    var w = today.getDay()
    m = checkTime(m)
    s = checkTime(s)
    mon = checkTime(mon)
    d = checkTime(d)
    switch (w) {
        case 1:
            w = "一";
            break;
        case 2:
            w = "二";
            break;
        case 3:
            w = "三";
            break;
        case 4:
            w = "四";
            break;
        case 5:
            w = "五";
            break;
        case 6:
            w = "六";
            break;
        case 0:
            w = "日";
            break;
    }
    document.getElementById('txt1').innerHTML = h + ":" + m
    document.getElementById('txt2').innerHTML = s
    document.getElementById('txt3').innerHTML = "星期" + w
    document.getElementById('txt4').innerHTML = y + "年" + mon + "月" + d + "日"
}
function checkTime(i) {
    if (i < 10) {
        i = "0" + i
    }
    return i
}
startTime()
setInterval(startTime,1000)

你可能感兴趣的:(时钟特效)