var tetCountdown = {
utc_vntet_offset: 0,
countdownInterval: null,
selectorId: "",
init: function (vntet_date, selectorId) {
this.utc_vntet_offset = vntet_date.getTime();
this.selectorId = selectorId;
},
countdown: function () {
var time_offset = tetCountdown.utc_vntet_offset - new Date().getTime();
if (time_offset > 0) {
seconds = Math.floor(time_offset / 1000);
minutes = Math.floor(seconds / 60);
hours = Math.floor(minutes / 60);
days = Math.floor(hours / 24);
hours = hours - (days * 24);
minutes = minutes - (days * 24 * 60) - (hours * 60);
seconds = seconds - (days * 24 * 60 * 60) - (hours * 60 * 60) - (minutes * 60);
$("#" + tetCountdown.selectorId).html("<i class='fa-fw fa fa-info'></i> Chỉ còn <strong>" + days + "</strong> ngày, " + hours + " giờ, " + minutes + " phút, " + seconds + " giây nữa là đến <strong>Tết Nguyên Đán Mậu Tuất 2018</strong>");
}
else {
time_offset = Math.abs(time_offset);
seconds = Math.floor(time_offset / 1000);
minutes = Math.floor(seconds / 60);
hours = Math.floor(minutes / 60);
days = Math.floor(hours / 24);
if (days <= 7) {
$("#" + tetCountdown.selectorId).html("<i class='fa-fw fa fa-info'></i> Chúc mừng năm mới xuân <strong>Mậu Tuất 2018</strong>");
}
}
},
start: function () {
this.countdownInterval = setInterval(this.countdown, 1000);
},
stop: function () {
clearInterval(this.countdownInterval);
}
};
tetCountdown.init(new Date(2018, 1, 16), "tet_countdown");
tetCountdown.start();
<div id="tet_countdown">
</div>
External resources loaded into this fiddle: