如何获取当前时间,然后使用jquery进行比较 [英] how to get current time and then compare them using jquery
本文介绍了如何获取当前时间,然后使用jquery进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
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 think it hard to compare with two time ,
我该怎么办?
谢谢
推荐答案
如果你真的想知道两个Date对象是否正好代表相同时间,或之前/之后,这很容易:只需通过 getTime()
方法比较两个日期,该方法返回对象的整数时间戳。例如,
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());
将返回true,如果现在或将来会返回false。
would return true if myDate is before 'now', false if it is now or in the future.
这篇关于如何获取当前时间,然后使用jquery进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文