Answer the question
In order to leave comments, you need to log in
How to fix now and end so that the remaining time is considered correct?
I found a ready-made timer js script and I'm trying to remake it so that the time is taken from the server, and not from the client. A very incomprehensible date format was originally used, so both end and php were transferred to UNIX format, but the difference between them is considered incorrect, please tell me how to fix this?
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Новый домен</title>
<link rel="stylesheet" href="styles.css" class="css">
<?php
$now = date('U');
$end = mktime(24, 0, 0, 12, 31, 2016);
?>
<script>
CountDownTimer('12/25/2015 12:00 PM', 'countdown'); //Month.Day
function CountDownTimer(dt, id){
var end = "<? echo $end ?>";
var _second = 1000;
var _minute = _second * 60;
var _hour = _minute * 60;
var _day = _hour * 24;
var timer;
function showRemaining() {
var now = "<? echo $now ?>"
console.log(end);
console.log(now);
var distance = end - now;
if (distance < 0) {
clearInterval(timer);
document.getElementById(id).innerHTML = 'EXPIRED!';
return;
}
var days = Math.floor(distance / _day);
var hours = Math.floor((distance % _day) / _hour);
var minutes = Math.floor((distance % _hour) / _minute);
var seconds = Math.floor((distance % _minute) / _second);
document.getElementById(id).innerHTML = days + 'days ';
document.getElementById(id).innerHTML += hours + 'hrs ';
document.getElementById(id).innerHTML += minutes + 'mins ';
document.getElementById(id).innerHTML += seconds + 'secs';
}
timer = setInterval(showRemaining, 1000);
}
</script>
</head>
<body>
<center>
<div id="countdown"></div>
<span id="span">remain</span>
</center>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Новый домен</title>
<link rel="stylesheet" href="styles.css" class="css">
<center>
<div id="countdown"></div>
<span id="span">remain</span>
</center>
<script>
CountDownTimer('12/25/2015 12:00 PM', 'countdown'); //Month.Day
function CountDownTimer(dt, id)
{
var end = new Date(dt);
var _second = 1000;
var _minute = _second * 60;
var _hour = _minute * 60;
var _day = _hour * 24;
var timer;
function showRemaining() {
var now = new Date();
var distance = end - now;
if (distance < 0) {
clearInterval(timer);
document.getElementById(id).innerHTML = 'EXPIRED!';
return;
}
var days = Math.floor(distance / _day);
var hours = Math.floor((distance % _day) / _hour);
var minutes = Math.floor((distance % _hour) / _minute);
var seconds = Math.floor((distance % _minute) / _second);
document.getElementById(id).innerHTML = days + 'days ';
document.getElementById(id).innerHTML += hours + 'hrs ';
document.getElementById(id).innerHTML += minutes + 'mins ';
document.getElementById(id).innerHTML += seconds + 'secs';
}
timer = setInterval(showRemaining, 1000);
}
</script>
</head>
<body>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
but the difference between them is considered incorrect, please tell me how to fix it?
<?php
date("D M j Y H:i:s TP");
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question