😢 http://ne-a-r.blogspot.com/2016/07/secepatnya-sayang-tunggu-aku.html
Last active
May 25, 2017 07:36
-
-
Save anovsiradj/ab4af91cb7e62ce8c48798356c123bd1 to your computer and use it in GitHub Desktop.
HTML CountDown
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
<script src="time-countdown.js"></script> | |
<script> | |
var website_expired = new Date('2046-05-22 00:00:00'); | |
var elm_result = document.createElement('div'); | |
window.addEventListener('load', function() { | |
document.body.appendChild(elm_result); | |
}); | |
time_countdown(website_expired, function(x) { | |
if (x === null) { | |
elm_result.innerHTML = 'Sekarang Sudah Lebih Dari Tanggal: <b>' + website_expired.toLocaleDateString('id-ID', {'day': 'numeric', month: "long", 'year': 'numeric' }) + '</b>'; | |
} else { | |
var t = x.days + ' Hari, ' + x.hours + ' Jam, ' + x.minutes + ' Menit, ' + x.seconds + ' Detik'; | |
elm_result.innerHTML = t; | |
} | |
}); | |
</script> |
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
<script> | |
// Jum, Mar 21 2014 23:40:48 | |
var end = new Date('05/22/2014 10:1 AM'); | |
var _second = 1000; | |
var _minute = _second * 60; | |
var _hour = _minute * 60; | |
var _day = _hour * 24; | |
var timer; | |
function showRemaining() { | |
var now = new Date(); | |
var distance = end - now; | |
if (distance < 0) { | |
clearInterval(timer); | |
document.getElementById('countdown').innerHTML = 'EXPIRED!'; | |
return; | |
} | |
var days = Math.floor(distance / _day); | |
var hours = Math.floor((distance % _day) / _hour); | |
var minutes = Math.floor((distance % _hour) / _minute); | |
var seconds = Math.floor((distance % _minute) / _second); | |
document.getElementById('countdown').innerHTML = days + 'days '; | |
document.getElementById('countdown').innerHTML += hours + 'hrs '; | |
document.getElementById('countdown').innerHTML += minutes + 'mins '; | |
document.getElementById('countdown').innerHTML += seconds + 'secs'; | |
} | |
timer = setInterval(showRemaining, 1000); | |
</script> | |
<div id="countdown"></div> |
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
function time_countdown(future_time, fn_callback) { | |
var fn = fn_callback || function() {}; | |
var _second = 1000; | |
var _minute = _second * 60; | |
var _hour = _minute * 60; | |
var _day = _hour * 24; | |
function time_countdown_core() { | |
var current_time = new Date(); | |
var delta_time = future_time - current_time; | |
if (delta_time <= 0) { | |
clearInterval(fn_interval); | |
fn(null); | |
} else { | |
var days = Math.floor(delta_time / _day); | |
var hours = Math.floor((delta_time % _day) / _hour); | |
var minutes = Math.floor((delta_time % _hour) / _minute); | |
var seconds = Math.floor((delta_time % _minute) / _second); | |
fn({ | |
'days': Math.floor(delta_time / _day), | |
'hours': Math.floor((delta_time % _day) / _hour), | |
'minutes': Math.floor((delta_time % _hour) / _minute), | |
'seconds': seconds = Math.floor((delta_time % _minute) / _second) | |
}); | |
} | |
} | |
var fn_interval = setInterval(time_countdown_core, 1000); | |
time_countdown_core(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment