Timestamp Countdown In Javascript And Php
I need some help to code a script that counts down the days, hours, minutes and seconds from a unix timestamp. timestamp is created with php And I wa
Solution 1:
First you have some PHP errors. It should be e.g.
<?phpecho time(); ?>
I'm using a timestamp in JavaScript for the ease of showing an example.
http://jsfiddle.net/pimvdb/AvXd3/
// the difference timestampvar timestamp = (Date.now() + 1000 * 60 * 60 * 24 * 3) - Date.now();
timestamp /= 1000; // from ms to secondsfunctioncomponent(x, v) {
returnMath.floor(x / v);
}
var $div = $('div');
setInterval(function() { // execute code each second
timestamp--; // decrement timestamp with one second each secondvar days = component(timestamp, 24 * 60 * 60), // calculate days from timestamp
hours = component(timestamp, 60 * 60) % 24, // hours
minutes = component(timestamp, 60) % 60, // minutes
seconds = component(timestamp, 1) % 60; // seconds
$div.html(days + " days, " + hours + ":" + minutes + ":" + seconds); // display
}, 1000); // interval each second = 1000 ms
Post a Comment for "Timestamp Countdown In Javascript And Php"