Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Print True in the console depending on a Specific Date

I am trying to print True in the console when a Specific date comes.

Here is my code :

setInterval(() => {
 if (new Date() == new Date("2022-06-18T06:27:00")) {
   console.log("true");
 } else {
   console.log("false");
 }
}, 1000);

But it keeps showing False

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

There is another way to do what I am thinking about?

Note: Both of new Date() and the Date which I have provided in the Stamp time are the same on the console

>Solution :

You can use the following:

setInterval(() => {
 if (new Date().toString() == new Date("2022-06-18T03:32:00").toString()) {
   console.log("true");
 } else {
   console.log("false");
 }
}, 1000);

var date = document.getElementById('date')
    var button = document.getElementById('submit')
    var result = document.getElementById('info')
    var reset = document.getElementById('reset')

    button.addEventListener('click', () => {
        date.disabled = true
        button.disabled = true
    var Timer = setInterval(() => {
            if (new Date().toString() == new Date(date.value).toString()) {
                result.innerHTML = "The date is: " + new Date().toString() + " Which is the same as the date you entered"
                clearInterval(Timer)
                date.disabled = false
                button.disabled = false
                return;
            }
            result.innerHTML = "Waiting for the date..."
           }, 1000);
    });

    reset.addEventListener('click', () => {
        input.disabled = false
        button.disabled = false
        result.innerHTML = "";
    })
<input type="datetime-local" id="date">
<button id="submit">Submit</button>
<button id="reset">Reset</button>
<p id="info"></p>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading