js count down - PhucVM2019/frontEnd GitHub Wiki
link demo https://codepen.io/AllThingsSmitty/pen/JJavZN
const second = 1000,
minute = second * 60,
hour = minute * 60,
day = hour * 24;
let countDown = new Date('03 31 2020 07:00:00 ').getTime(),
x = setInterval(function() {
let now = new Date().getTime(),
distance = countDown - now;
document.getElementById('days').innerText = Math.floor(distance / (day)),
document.getElementById('hours').innerText = Math.floor((distance % (day)) / (hour)),
document.getElementById('minutes').innerText = Math.floor((distance % (hour)) / (minute)),
document.getElementById('seconds').innerText = Math.floor((distance % (minute)) / second);
//do something later when date is reached
//if (distance < 0) {
// clearInterval(x);
// 'IT'S MY BIRTHDAY!;
//}
}, second)
thực hành tại fpts
var h = textTime.toString().split(':')[0]
var m = textTime.toString().split(':')[1]
var dd = trimmedString.toString().split('/')[0]
var mm = trimmedString.toString().split('/')[1]
var yyyy = trimmedString.toString().split('/')[2]
console.log(h);
console.log(m);
console.log(dd);
console.log(mm)
console.log(yyyy);
//count down
const second = 1000,
minute = second * 60,
hour = minute * 60,
day = hour * 24;
var datetime = mm + " " + dd + "," + yyyy +" "+ h + ":" + m + ":00";
console.log(datetime);
let countDown = new Date(datetime).getTime(),
x = setInterval(function () {
let now = new Date().getTime(),
distance = countDown - now;
document.getElementById('days').innerText = Math.floor(distance / (day)),
document.getElementById('hours').innerText = Math.floor((distance % (day)) / (hour)),
document.getElementById('minutes').innerText = Math.floor((distance % (hour)) / (minute)),
document.getElementById('seconds').innerText = Math.floor((distance % (minute)) / second);
}, second)