Поскольку заголовок говорит, что я не очень хорош в этом, и я боюсь, как это сделать, когда запускаются таймеры событий, он будет обратный отсчет до тех пор, пока событие не начнет получать время с сервера и не рассчитывает на время браузера / клиента? В текущем случае все пропустят событие, так как большинство из них имеют разные часовые пояса и его неправильное 🙂
Дайте мне подсказку, пожалуйста. Вот полная функция:
<?php $d = date('DM d YH:i:s O'); ?> <script type="text/javascript"> var currdate = new Date(<?php $d; ?>); 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>
<?php $d = date('DM d YH:i:s O'); echo " <script> var currdate = new Date($d); </script> "; ?>