C
C
Cyril2021-03-04 09:53:21
JavaScript
Cyril, 2021-03-04 09:53:21

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

1 answer(s)
B
Borisvvv, 2021-11-06
@Borisvvv

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 question

Ask a Question

731 491 924 answers to any question