Keith jQuery Count down time working with server time with Ajax
Javascript code on html file
<script>
function serverTime() {
var time = null;
$.ajax({url: 'serverTime.php',
async: false, dataType: 'text',
success: function(text) {
time = new Date(text);
}, error: function(http, message, exc) {
time = new Date();
}});
return time;
}
$(document).ready(function () {
$('#120').countdown({
until: new Date(2014, 03 - 1, 30),
format: 'DHMS',
serverSync: serverTime
});
});
</script>
PHP file - this should upload to your server<?php
$now = new DateTime(null, new DateTimeZone('Asia/Kolkata'));
echo $now->format("M j, Y H:i:s O")."\n";
?>
No comments:
Post a Comment