<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"> <title>Время намаза по КЧР</title> <script type="text/javascript"> g=<?php echo date("Y"); ?>; // тут я беру год который на сервере y_u_1=new Date(g, 11,1,06, 05); // дата события function on() { // эта функция которая отвечает за то чтобы таймер начала работать через 5 секунд timeoutId = setInterval(f_y_u_1, 5000); // эта функция которая отвечает за то чтобы таймер начала работать через 5 секунд clearInterval(id); // эта функция которая отвечает за то чтобы таймер начала работать через 5 секунд function f_y_u_1() { v=y_u_1; td = new Date(<?= (time() * 1000) ?>); //ДЕЛО В ТОМ ЧТО КОГДА ТУТ БРАЛОСЬ ВРЕМЯ НА JAVA SCRIPT - ШЕЛ ТАЙМЕР А ТЕПЕРЬ ОН ПРОСТО СТОИТ td = Math.floor((v-td)/1000); tsec=td%60; td=Math.floor(td/60); if(tsec<10)tsec='0'+tsec; tmin=td%60; td=Math.floor(td/60); if(tmin<10)tmin='0'+tmin; tj=td%24; td=Math.floor(td/24); if (td>0){tmr=td +" дней "+ tj+" чаc. "+tmin+" мин. "+tsec+" c.";} else {if (tj>0){tmr=tj+" чаc. "+tmin+" мин. "+tsec+" c.";}else{if (tmin>0){tmr=tmin+" мин. "+tsec+" c.";} else{if (tsec>0){tmr=tsec+" c.";} else{f_y_u_1()};};};};document.getElementById('t').innerHTML=tmr;window.setTimeout("f_y_u_1()",1000);}; } </script> </head> <body> <script type="text/javascript"> on(); </script> <p style="font-size:30px" align=""> До события осталось: <br/> <br/> <span id="t" ></span> </p> </body> </html> 

Update

Now we will talk about 28 lines. So there is td = new Date (<? = (Time () * 1000)?>). It used to be this way: td = new Date () - and the clock on the site was ticking, and now they just stand until the page is updated, time does not change, and before that the timer went online.

  • complete the question normally - zb '
  • Now we will talk about 28 lines. So there is td = new Date (<? = (Time () * 1000)?>). It used to be so td = new Date () - and the clock on the site was ticking and now they just stand - until the page updates the time does not change - and earlier the timer went online - Ruslan904322

1 answer 1

Your code is unreadable! But the problem is that the variable td in line 28 always has the same value all the time the script is executed. To avoid this, you need to move the server time out of the function limits, and inside yourself change the time value by one second. Below is a fully working version.

  <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"> <title>Время намаза по КЧР</title> <script type="text/javascript"> var y_u_1 = new Date(<?php echo date("Y"); ?>, 11, 1, 06, 05); // дата события var initial_time = <?php echo time() * 1000; ?>; var intervalId = 0; var delay = 1000; function on() { setTimeout(f_y_u_1, 5000); function f_y_u_1() { var v, td, tsec, tmin, tj, tmr; v = y_u_1; td = new Date(initial_time); //ДЕЛО В ТОМ ЧТО КОГДА ТУТ БРАЛОСЬ ВРЕМЯ НА JAVA SCRIPT - ШЕЛ ТАЙМЕР А ТЕПЕРЬ ОН ПРОСТО СТОИТ td = Math.floor((v - td) / 1000); tsec = td % 60; td = Math.floor(td / 60); if ( tsec < 10 ) { tsec = '0' + tsec; } tmin = td % 60; td = Math.floor(td / 60); if ( tmin < 10 ) { tmin = '0' + tmin; } tj = td % 24; td = Math.floor(td / 24); if ( td > 0 ) { tmr = td + " дней " + tj + " чаc." + tmin + " мин." + tsec + " c."; } else { if ( tj > 0 ) { tmr = tj + " чаc. " + tmin + " мин." + tsec + " c."; } else { if ( tmin > 0 ) { tmr = tmin + " мин. " + tsec + " c."; } else { if ( tsec > 0 ) { tmr = tsec + " c."; } else { f_y_u_1(); } } } } document.getElementById('t').innerHTML = tmr; initial_time += delay; if ( !intervalId ) { intervalId = setInterval(f_y_u_1, delay); } } } </script> </head> <body> <p style="font-size:30px" align=""> До события осталось: <br/> <br/> <span id="t"></span> </p> <script type="text/javascript"> on(); </script> </body> </html> 
  • does not work ((((((((((( - Ruslan 904322
  • I'm sorry! but it really works, thank you very much. Zhenyab, you can not even imagine how much I was suffering - thank you very much !!!!!!! - Ruslan904322