php - Server time instead of client time JAVASCRIPT -
is possible use script server time instead of client time. (for checking if time past) uses client time , thats problem. (maybe php??)
<script> var end = new date('02/19/2012 10:1 am'); var _second = 1000; var _minute = _second * 60; var _hour = _minute * 60; var _day = _hour * 24; var timer; function showremaining() { var = new date(); var distance = end - now; if (distance < 0) { clearinterval(timer); document.getelementbyid('countdown').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('countdown').innerhtml = days + 'days '; document.getelementbyid('countdown').innerhtml += hours + 'hrs '; document.getelementbyid('countdown').innerhtml += minutes + 'mins '; document.getelementbyid('countdown').innerhtml += seconds + 'secs'; } timer = setinterval(showremaining, 1000); </script> <div id="countdown"></div>
you can time ajax request, or use this:
<?php $now = date('d-m-y'); $end= "01-01-2013" $date = strtotime($end) - strtotime($now); $days = date('d', $date); $monthes= date('m', $date); $years= date('y', $date); ?> <script> var days = "<?= $days ?>"; var monthes= "<?= $monthes?>"; var years= "<?= $years?>"; document.getelementbyid('countdown').innerhtml = days+ ' days'; document.getelementbyid('countdown').innerhtml += monthes+ ' monthes'; document.getelementbyid('countdown').innerhtml += years+ ' years'; </script>
Comments
Post a Comment