日期:2014-05-18  浏览次数:20706 次

如何判断日期是否过期??
例如:日期A   日期B   日期C   (格式全为日期型)

如果   B   小于A   输出:还没开始  
如果   B   大于C   输出:已经结束

否则   正在进行中。。。。


请请教这个怎么实现。。。。我用“> 、 <”判断不管用!

------解决方案--------------------
分别获得这三个日期的毫秒数,然后进行比较!

DATE API 中有这个函数 我忘了
呵呵!
------解决方案--------------------
Calendar now = Calendar.getInstance();
Calendar auditTime = Calendar.getInstance();

auditTime.clear();
auditTime.setTime(vktask.getEndDate());//vktask.getEndDate()取出的是java.util.Date型

if (auditTime.before(now)) {
}else{
}
------解决方案--------------------
可以使用 Date 类的 compareTo() 方法来比较。

data1.compareTo(data2); 会返回一个整数值,小于0,这个时间在前;大于0,这个时间在后;等于0,这两个时间相等。
------解决方案--------------------
对,直接把2007-06-06 15:15:00 这种格式的时间转化成毫秒数,然后直接比较!
------解决方案--------------------
before
public boolean before(Date when)
Tests if this date is before the specified date.

Parameters:
when - a date.
Returns:
true if and only if the instant of time represented by this Date object is strictly earlier than the instant represented by when; false otherwise.

--------------------------------------------

after
public boolean after(Date when)
Tests if this date is after the specified date.

Parameters:
when - a date.
Returns:
true if and only if the instant represented by this Date object is strictly later than the instant represented by when; false otherwise.

--------------------------------------------


API

------解决方案--------------------
同意 bao110908(长牙了,好痛)