如何在以下其中一个倒计时时间功能上添加不同的日期?

时间:2014-11-27 11:05:07

标签: javascript

以下javascript代码包含3个函数,其中2个每天计算次数,CSW Timer每7天(星期日)发生一次,但是,我想让BDWTimer()不是每天而是仅在星期三(3) )和星期五(5)。我正在努力如何做到这一点,因为此时它只是每天特定的时间?任何帮助我如何做到这一点表示赞赏...感谢您的时间!

例如:如果我们是星期一 - BDW计时器应该显示2(星期三的天数):X小时:X分钟:X秒..如果我们星期三它应该显示0天其余的,如果一天都完成(总共4个事件)继续到下个星期五,那么:2(星期三到星期日):X小时:X分钟:X秒..

<script>
var currdate = new Date();
var currdate = new Date();
var day = currdate.getDay();
var hrs = currdate.getHours();
var hrs0 = currdate.getHours();
var hrs00 = currdate.getHours();
var mins = currdate.getMinutes();
var secs = currdate.getSeconds();
var CSWday = 7;
var CSWhrs = 19;
var FThrs1 = 6;
var FThrs2 = 14;
var FThrs3 = 22;
var BDWhrs1 = 5;
var BDWhrs2 = 11;
var BDWhrs3 = 17;
var BDWhrs4 = 23;
var FTmins1 = 59;
var FTsecs1 = 60;
var hrsOut = 0;
var hrsOut2 = 0;

var hrs1 = FThrs1 - hrs;
var hrs2 = FThrs2 - hrs;
var hrs3 = FThrs3 - hrs;

var hrs01 = BDWhrs1 - hrs0;
var hrs02 = BDWhrs2 - hrs0;
var hrs03 = BDWhrs3 - hrs0;
var hrs04 = BDWhrs4 - hrs0;

var day = CSWday - day;
var hrs001 = CSWhrs - hrs00;

if (day == 7)
    day = 0;

if ((hrs > 22) || ((hrs >= 0) && (hrs < 7)))
{
    if (hrs > 22)
        hrsOut = 7;
    else
        hrsOut = hrs1;
}
if ((hrs > 6) && (hrs < 15))
    hrsOut = hrs2;
if ((hrs > 14) && (hrs < 23))
    hrsOut = hrs3;

if ((hrs0 > 23) || ((hrs0 >= 0) && (hrs0 < 6)))
{
    if (hrs0 > 23)
        hrsOut2 = 6;
    else
        hrsOut2 = hrs01;
}
if ((hrs0 > 5) && (hrs0 < 12))
    hrsOut2 = hrs02;
if ((hrs0 > 11) && (hrs0 < 18))
    hrsOut2 = hrs03;
if ((hrs0 > 17) && (hrs0 <= 23))
    hrsOut2 = hrs04;

mins = FTmins1 - mins;
secs = FTsecs1 - secs;

var counter=setInterval(FTTimer, 1000);
var counter=setInterval(BDWTimer, 1000);
var counter=setInterval(CSWTimer, 1000);

function FTTimer()
{
    secs=secs-1;

    if (hrsOut < 0)
    {
        clearInterval(counter);
    }
    else if (mins < 0)
    {
        secs = 59;
        mins = 59;
        hrsOut = hrsOut - 1;
        return;
    }
    else if (secs < 0)
    {
        secs = 59;
        mins = mins - 1;
        return;
    }

    if (secs < 10 && mins < 10 && hrsOut < 10)
        document.getElementById("FTTimer").innerHTML="0"+hrsOut+":0"+mins+":0"+secs;
    else if (mins < 10 && hrsOut < 10)
        document.getElementById("FTTimer").innerHTML="0"+hrsOut+":0"+mins+":"+secs;
    else if (secs < 10 && hrsOut < 10)
        document.getElementById("FTTimer").innerHTML="0"+hrsOut+":"+mins+":0"+secs;
    else if (secs < 10 && mins < 10)
        document.getElementById("FTTimer").innerHTML=hrsOut+":0"+mins+":0"+secs;
    else if (hrsOut < 10)
        document.getElementById("FTTimer").innerHTML="0"+hrsOut+":"+mins+":"+secs;
    else if (mins < 10)
        document.getElementById("FTTimer").innerHTML=hrsOut+":0"+mins+":"+secs;     
    else if (secs < 10)
        document.getElementById("FTTimer").innerHTML=hrsOut+":"+mins+":0"+secs;
    else
        document.getElementById("FTTimer").innerHTML=hrsOut+":"+mins+":"+secs;
}

function BDWTimer()
{
    if (hrsOut2 < 0)
    {
        clearInterval(counter);
    }
    else if (mins < 0)
    {
        secs = 59;
        mins = 59;
        hrsOut2 = hrsOut2 - 1;
        return;
    }
    else if (secs < 0)
    {
        secs = 59;
        mins = mins - 1;
        return;
    }

    if (secs < 10 && mins < 10 && hrsOut2 < 10)
        document.getElementById("BDWTimer").innerHTML="0"+hrsOut2+":0"+mins+":0"+secs;
    else if (mins < 10 && hrsOut2 < 10)
        document.getElementById("BDWTimer").innerHTML="0"+hrsOut2+":0"+mins+":"+secs;
    else if (secs < 10 && hrsOut2 < 10)
        document.getElementById("BDWTimer").innerHTML="0"+hrsOut2+":"+mins+":0"+secs;
    else if (secs < 10 && mins < 10)
        document.getElementById("BDWTimer").innerHTML=hrsOut2+":0"+mins+":0"+secs;
    else if (hrsOut2 < 10)
        document.getElementById("BDWTimer").innerHTML="0"+hrsOut2+":"+mins+":"+secs;
    else if (mins < 10)
        document.getElementById("BDWTimer").innerHTML=hrsOut2+":0"+mins+":"+secs;       
    else if (secs < 10)
        document.getElementById("BDWTimer").innerHTML=hrsOut2+":"+mins+":0"+secs;
    else
        document.getElementById("BDWTimer").innerHTML=hrsOut2+":"+mins+":"+secs;
}

function CSWTimer()
{
    if (day < 0)
    {
        day = 6;
        return;
    }
    else if (hrs001 < 0)
    {
        if (hrs001 == -1)
            hrs001 = 23;
        else if (hrs001 == -2)
            hrs001 = 22;
        else if (hrs001 == -3)
            hrs001 = 21;
        else if (hrs001 == -4)
            hrs001 = 20;
        day = day - 1;
        return;
    }
    else if (mins < 0)
    {
        secs = 59;
        mins = 59;
        hrs001 = hrs001 - 1;
        return;
    }
    else if (secs < 0)
    {
        secs = 59;
        mins = mins - 1;
        return;
    }

    if (secs < 10 && mins < 10 && hrs001 < 10)
        document.getElementById("CSWTimer").innerHTML=day+":0"+hrs001+":0"+mins+":0"+secs;
    else if (mins < 10 && hrs001 < 10)
        document.getElementById("CSWTimer").innerHTML=day+":0"+hrs001+":0"+mins+":"+secs;
    else if (secs < 10 && hrs001 < 10)
        document.getElementById("CSWTimer").innerHTML=day+":0"+hrs001+":"+mins+":0"+secs;
    else if (secs < 10 && mins < 10)
        document.getElementById("CSWTimer").innerHTML=day+":"+hrs001+":0"+mins+":0"+secs;
    else if (hrs001 < 10)
        document.getElementById("CSWTimer").innerHTML=day+":0"+hrs001+":"+mins+":"+secs;
    else if (mins < 10)
        document.getElementById("CSWTimer").innerHTML=day+":"+hrs001+":0"+mins+":"+secs;        
    else if (secs < 10)
        document.getElementById("CSWTimer").innerHTML=day+":"+hrs001+":"+mins+":0"+secs;
    else
        document.getElementById("CSWTimer").innerHTML=day+":"+hrs001+":"+mins+":"+secs;
}
</script>

0 个答案:

没有答案