Jak obliczać czas od daty serwera a nie lokalnej? ale tu proszę też o pomoc w zrozumieniu, czy to ma sens? bo kto zmienia datę systemową?, poza tym dojdą kolejne linijki kodu gdy mamy różnice w czasie co na razie jest już czarną magią dla mnie
Jak dodać kilka wydarzeń (różnych odliczań) na jednej stronie z jednego kodu
Mój kod na teraz wygląda tak
JavaScript
var countDownDateTime = new Date("2017-11-12 12:00:00").getTime(); var myInterval = setInterval(function () { "use strict"; var currentDateTime = new Date().getTime(); var diff = countDownDateTime - currentDateTime; var days = Math.floor(diff / (1000 * 60 * 60 * 24)); var hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); var minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60)); var seconds = Math.floor((diff % (1000 * 60)) / 1000); if (days<10) {days = '0' + days;} if (hours<10) {hours ='0' + hours;} if (minutes<10) {minutes ='0' + minutes;} if (seconds<10) {seconds ='0' + seconds;} document.getElementById("days").innerHTML = days; document.getElementById("hours").innerHTML = hours; document.getElementById("minutes").innerHTML = minutes; document.getElementById("seconds").innerHTML = seconds; if (diff < 0) { clearInterval(myInterval); var elem = document.getElementById("clear"); elem.parentNode.removeChild(elem); } }, 1000);
Kod Html