If you want to create a countdown timer for your website, you can do so with Javascript. But, there are some things you need to look out for concerning dates. Below is a code snippet for creating a Javascsript countdown timer.
$(document).ready(function() {
// set the date we're counting down to
// if the target date should be local to a user's time zone, e.g. the next new year,
// then just enter the date, e.g. "Jan 1, 2015 00:00:00"
// if the target date should be fixed to one time zone,
// e.g. for a live, online event that will take place at the same time regardless of a user's time zone,
// then enter the date in universal format, e.g. Apr 24, 2014 10:00:00 GMT-0700
// this example is for a target date that is on April 24, 2014 at 10 AM Pacific time (USA)
var target_date = new Date("Apr 24, 2014 10:00:00 GMT-0700").getTime();
// variables for time units
var days, hours, minutes, seconds;
// get tag element
var countdown = document.getElementById("countdown");
// update the tag with id "countdown" every 1 second
var timerId = setInterval(function () {
// find the amount of "seconds" between now and target
var current_date = new Date().getTime();
var seconds_left = (target_date - current_date) / 1000;
// do some time calculations
days = parseInt(seconds_left / 86400);
seconds_left = seconds_left % 86400;
hours = parseInt(seconds_left / 3600);
seconds_left = seconds_left % 3600;
minutes = parseInt(seconds_left / 60);
seconds = parseInt(seconds_left % 60);
// insert the time
$days.text(days);
$hours.text(hours);
$minutes.text(minutes);
$seconds.text(seconds);
}, 1000);
});
Continue reading Javascript Countdown Timer