0

I started to learn Node.js. But I don't understand how to work with time, my question is probably not correct. But I will be grateful for any answer.


add one day to the current date:

var date = new Date();
var ok = date.setDate(date.getDate() + 1)
var result = new Date(ok);

console.log(result.toLocaleString())

Now I want to compare, down to the seconds, whether a given date has passed from the current
I found this code on my search:
But I doubt it's right for me.

var givenDate = new Date('June 7, 2022');
if (Date.now() > givenDate.getTime()) {
  // the date has passed
} else {
  // the date has not passed
}
  • Why do you doubt it? Does it not work? (and if it doesn't, what problems do you face?) – kelsny Mar 06 '23 at 03:05
  • Re `new Date('June 7, 2022')`, see [*Why does Date.parse give incorrect results?*](https://stackoverflow.com/questions/2587345/why-does-date-parse-give-incorrect-results) The date comparison checks to the millisecond. – RobG Mar 06 '23 at 12:12

0 Answers0