其他分享
首页 > 其他分享> > jQuery每秒刷新显示当前时间

jQuery每秒刷新显示当前时间

作者:互联网

JavaScript代码

setInterval(
    function getNowTime() {
        var nowTime = new Date();
        var nowYear = nowTime.getFullYear().toString();		//获取当前年份
        var nowMonth = (nowTime.getMonth() + 1).toString();	//获取当前月份
        var nowDay = nowTime.getDate().toString();			//获取当前日期
        var nowHours = nowTime.getHours().toString();		//获取当前小时数
        var nowMin = nowTime.getMinutes().toString();		//获取当前分钟数
        var nowSecond = nowTime.getSeconds().toString();    //获取当前秒数
        if (nowYear < 10) { nowYear = "0" + nowYear };
        if (nowMonth < 10) { nowMonth = "0" + nowMonth };
        if (nowDay < 10) { nowDay = "0" + nowDay };
        if (nowHours < 10) { nowHours = "0" + nowHours };
        if (nowMin < 10) { nowMin = "0" + nowMin };
        if (nowSecond < 10) { nowSecond = "0" + nowSecond };
        var time = nowYear + "年" + nowMonth + "月" + nowDay + "日" + nowHours + ":" + nowMin + ":" + nowSecond;
        $("#timenow").text("当前时间:" + time);
    }, 1000);

jQuery定时器特效

标签:jQuery,10,nowSecond,nowTime,toString,刷新,var,nowYear,每秒
来源: https://www.cnblogs.com/gygg/p/11813840.html