Answer the question
In order to leave comments, you need to log in
How to make a tilde timer that will change dates through JS?
Hello everyone;)
Please tell me if it is possible to make such a timer on a tilde:
Which will work at 13.00 daily
AND change the time to 19h the next day.
Example:
If I go to the site now, the webinar will be indicated on February 4, 19.00.
If I go to the site at 13.01, the site will indicate that the webinar is February 5, 19.00
Answer the question
In order to leave comments, you need to log in
Hello.
Yes, you can.
I used such code.
let date = new Date();
let min = date.getMinutes();
let hh = date.getHours();
let dd = date.getDate();
let mm = date.getMonth() + 1; //так как месяца начинаются с 0
let yy = date.getFullYear();
(hh <= 12) ? dd += 1 : dd += 2;
if (min < 10) min = "0" + min;
if (hh < 10) hh = "0" + hh;
if (dd < 10) dd = "0" + dd;
if (mm < 10) mm = "0" + mm;
let neededDate = `${dd}.${mm}.${yy} ${hh}:${min}`;
let div = document.createElement('div');
div.innerHTML = `<p> ${neededDate} </p>`;
document.body.append(div);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question