Skip to content

Instantly share code, notes, and snippets.

@hrialan
Last active March 30, 2022 16:04
Show Gist options
  • Save hrialan/bc6f8be83a66c2d893b99c9727c69b3d to your computer and use it in GitHub Desktop.
Save hrialan/bc6f8be83a66c2d893b99c9727c69b3d to your computer and use it in GitHub Desktop.
[Timer template javascript]
jQuery(function ($) {
var date = new Date('April 1, 2022 17:15:00');
var days = $('#days');
var hours = $('#hours');
var minutes = $('#minutes');
var seconds = $('#seconds');
setDate();
function setDate() {
var now = new Date();
var s = ((date.getTime() - now.getTime()) / 1000);
var d = Math.floor(s / 86400);
days.html('<h2>'+ (d<0? 0 : d) +'</h2><p>J.</p>');
s -= d *86400;
var h = Math.floor(s / 3600);
hours.html( '<h2>'+ (d<0? 0 : h) +'</h2><p>H.</p>');
s -= h*3600;
var m = Math.floor(s / 60);
minutes.html('<h2>'+ (d<0? 0 : m) +'</h2><p>M.</p>');
s -= m*60;
s=Math.floor(s);
seconds.html( '<h2>'+ (d<0? 0 : s) +'</h2><p>S.</p>');
setTimeout(setDate,1000);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment