Задать вопрос

Сделать отсчёт времени?

Здравствуйте, помогите поправить код,
1. изменить дату под 0000-00-00 00:00:00 «2025-04-16 15:43:01»
2. Подстроившие по московскому времени автоматически, типо такого плана:

function updateCountdown() {
		const now = new Date(new Date().toLocaleString('en-US', { timeZone: 'Europe/Moscow' }));

3. После окончание переадресация, обновления страницы происходило.

<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8" />
    <title>Время</title>
</head>
<body>



<?
$time_left = 'August 15, 2025 02:53:37'; ?>

<div class="form-time-pay">
<div id="payment_the_end" class="time-pay">Осталось </div>
<span id="payment_left"></span>
</div>
<script>
// Set the date we're counting down to
var countDownDate = new Date("<? echo $time_left ?>").getTime();

// Update the count down every 1 second
var x = setInterval(function() {

// Get todays date and time
var now = new Date().getTime();
    
// Find the distance between now an the count down date
var distance = countDownDate - now;
    
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);

if(distance > 0) {
	
// Output the result in an element with id="payment_left"
document.getElementById("payment_left").innerHTML = minutes + "м " + seconds + "с ";
		
}
	
// If the count down is over, write some text 
if(distance < 0) {

clearInterval(x);

document.getElementById("payment_the_end").innerHTML = "Время истекло для оплаты.";

}

}, 1);

</script>








</body>
</html>
  • Вопрос задан
  • 26 просмотров
Подписаться 1 Простой Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы