Last active
March 30, 2022 16:04
-
-
Save hrialan/bc6f8be83a66c2d893b99c9727c69b3d to your computer and use it in GitHub Desktop.
[Timer template javascript]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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