I need to work on a countdown counter for a specific future date-time. I managed to use following counter http://www.blacktie.co/demo/counter/ and made some minor changes to it when i was almost done i noticed that this counter use local system date & when i change the system date it is reflected on the counter. How can this script be modified to so that it will take GMT date from server when it starts counter rather than local date.
So that every users irrespective of their location will see the exact date-time of even happening in India.
Fiddle example http://jsfiddle.net/635hf1je/1/
script
(function ($) {
/**
* Set your date here (YEAR, MONTH (0 for January/11 for December), DAY, HOUR, MINUTE, SECOND)
* according to the GMT+0 Timezone
**/
var launch = new Date(2014, 11, 04, 12, 00);
/**
* The script
**/
var message = $('#message');
var days = $('#days');
var hours = $('#hours');
var minutes = $('#minutes');
var seconds = $('#seconds');
setDate();
function setDate() {
var now = new Date();
if (launch < now) {
days.html('<h1>0</H1><p>Day</p>');
hours.html('<h1>0</h1><p>Hour</p>');
minutes.html('<h1>0</h1><p>Minute</p>');
seconds.html('<h1>0</h1><p>Second</p>');
message.html('coming soon...');
} else {
var s = -now.getTimezoneOffset() * 60 + (launch.getTime() - now.getTime()) / 1000;
var d = Math.floor(s / 86400);
days.html('<h1>' + d + '</h1><p>Day' + (d > 1 ? 's' : ''), '</p>');
s -= d * 86400;
var h = Math.floor(s / 3600);
hours.html('<h1>' + h + '</h1><p>Hour' + (h > 1 ? 's' : ''), '</p>');
s -= h * 3600;
var m = Math.floor(s / 60);
minutes.html('<h1>' + m + '</h1><p>Minute' + (m > 1 ? 's' : ''), '</p>');
s = Math.floor(s - m * 60);
seconds.html('<h1>' + s + '</h1><p>Second' + (s > 1 ? 's' : ''), '</p>');
setTimeout(setDate, 1000);
message.html('coming soon...');
}
}
})(jQuery);
Are you looking for this : http://jsfiddle.net/lotusgodkk/635hf1je/2/ ?
Just convert the Javascript Date object into UTC.
in
setDate()
function.