开发者

how to get current time and then compare them using jquery

开发者 https://www.devze.com 2023-01-13 19:58 出处:网络
this is my code: var currentTime = new Date() var month = currentTime.getMonth() + 1 var day = currentTime.getDate()

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 + "/" + 开发者_StackOverflowday + "/" + year)

but , i think it hard to compare with two time ,

what can i do ?

thanks


If you really want to know whether two Date objects represent precisely the same time, or are before/after one another, it's quite easy: just compare the two Dates via the getTime() method, which returns an integer timestamp for the object. For example,

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

would return true if myDate is before 'now', false if it is now or in the future.

0

精彩评论

暂无评论...
验证码 换一张
取 消