$(document).ready(function() { let clock; // Grab the current date let currentDate = new Date(); // Target future date/24 hour time/Timezone let targetDate = moment.tz("2022-06-30 23:59", "Asia/Jakarta"); // Calculate the difference in seconds between the future and current date let diff = targetDate / 1000 - currentDate.getTime() / 1000; if (diff <= 0) { // If remaining countdown is 0 clock = $(".clock").FlipClock(0, { clockFace: "DailyCounter", countdown: true, autostart: false }); console.log("Date has already passed!") } else { // Run countdown timer clock = $(".clock").FlipClock(diff, { clockFace: "DailyCounter", countdown: true, callbacks: { stop: function() { console.log("Timer has ended!") } } }); // Check when timer reaches 0, then stop at 0 setTimeout(function() { checktime(); }, 1000); function checktime() { t = clock.getTime(); if (t <= 0) { clock.setTime(0); } setTimeout(function() { checktime(); }, 1000); } } }); function generate_year_range(start, end) { var years = ""; for (var year = start; year <= end; year++) { years += ""; } return years; } today = new Date(); currentMonth = today.getMonth(); currentYear = today.getFullYear(); selectYear = document.getElementById("year"); selectMonth = document.getElementById("month"); createYear = generate_year_range(1970, 2050); /** or * createYear = generate_year_range( 1970, currentYear ); */ document.getElementById("year").innerHTML = createYear; var calendar = document.getElementById("calendar"); var lang = calendar.getAttribute('data-lang'); var months = ""; var days = ""; var monthDefault = ["Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember"]; var dayDefault = ["Ming", "Sen", "Sel", "Rab", "Kam", "Jum", "Sab"]; if (lang == "en") { months = monthDefault; days = dayDefault; } else if (lang == "id") { months = ["Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember"]; days = ["Ming", "Sen", "Sel", "Rab", "Kam", "Jum", "Sab"]; } else if (lang == "fr") { months = ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"]; days = ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"]; } else { months = monthDefault; days = dayDefault; } var $dataHead = ""; for (dhead in days) { $dataHead += "" + days[dhead] + ""; } $dataHead += ""; //alert($dataHead); document.getElementById("thead-month").innerHTML = $dataHead; monthAndYear = document.getElementById("monthAndYear"); showCalendar(currentMonth, currentYear); function next() { currentYear = (currentMonth === 11) ? currentYear + 1 : currentYear; currentMonth = (currentMonth + 1) % 12; showCalendar(currentMonth, currentYear); } function previous() { currentYear = (currentMonth === 0) ? currentYear - 1 : currentYear; currentMonth = (currentMonth === 0) ? 11 : currentMonth - 1; showCalendar(currentMonth, currentYear); } function jump() { currentYear = parseInt(selectYear.value); currentMonth = parseInt(selectMonth.value); showCalendar(currentMonth, currentYear); } //==show calendar dan seterusnya di calendarJS.php==// function showCalendar(month, year) { const hari = [1,16,22,30]; var firstDay = ( new Date( year, month ) ).getDay(); tbl = document.getElementById("calendar-body"); tbl.innerHTML = ""; monthAndYear.innerHTML = months[month] + " " + year; selectYear.value = year; selectMonth.value = month; // creating all cells var date = 1; for ( var i = 0; i < 6; i++ ) { var row = document.createElement("tr"); for ( var j = 0; j < 7; j++ ) { if ( i === 0 && j < firstDay ) { cell = document.createElement( "td" ); cellText = document.createTextNode(""); cell.appendChild(cellText); row.appendChild(cell); } else if (date > daysInMonth(month, year)) { break; } else { cell = document.createElement("td"); cell.setAttribute("data-date", date); cell.setAttribute("data-month", month + 1); cell.setAttribute("data-year", year); cell.setAttribute("data-month_name", months[month]); cell.className = "date-picker"; cell.innerHTML = "" + date + ""; if ( date === today.getDate() && year === today.getFullYear() && month === today.getMonth() ) { cell.className = "date-picker selected"; } if(inArray(date, hari)){ cell.className = "date-picker selected2"; } row.appendChild(cell); date++; } } tbl.appendChild(row); } } function daysInMonth(iMonth, iYear) { return 32 - new Date(iYear, iMonth, 32).getDate(); } function inArray(needle, haystack) { var length = haystack.length; for(var i = 0; i < length; i++) { if(haystack[i] == needle) return true; } return false; }