How to get current time and then compare them using jquery

this is my code:

    var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()

alert(minutes+"/"+hours+"/"+month + "/" + day + "/" + year)

but I find it difficult to compare this with two points,

What can I do?

thank

+3
source share
1 answer

If you really want to know if two Date objects represent exactly the same time or are before / after one another, it's pretty simple: just compare the two dates using a method getTime()that returns an integer timestamp for the object. For instance,

var date1 = myDate,
    date2 = new Date();
return (date1.getTime() < date2.getTime());

will return true if myDate is up to "now", false if it is now or in the future.

+6
source

Source: https://habr.com/ru/post/1762153/


All Articles