可以使用 Date 类的 compareTo() 方法来比较。data1.compareTo(data2); 会返回一个整数值,小于0,这个时间在前;大于0,这个时间在后;等于0,这两个时间相等。
SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = new Date(); date = s.parse("2007-06-06 15:15:00"); Calendar calendar = new Calendar(); calendar.setTime(date); long time = calendar.getTimeInMillis() / 1000;你按照这个思路去做,就可以了 !
写错了,修正如下:SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = new Date(); date = s.parse("2007-06-06 15:15:00"); Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT+8:00"));calendar.setTime(date); long time = calendar.getTimeInMillis() / 1000;
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
呵呵!
Calendar auditTime = Calendar.getInstance();auditTime.clear();
auditTime.setTime(vktask.getEndDate());//vktask.getEndDate()取出的是java.util.Date型if (auditTime.before(now)) {
}else{
}
而且已经是Date型的了。。怎么判断??
Date date = new Date();
date = s.parse("2007-06-06 15:15:00");
Calendar calendar = new Calendar();
calendar.setTime(date);
long time = calendar.getTimeInMillis() / 1000;你按照这个思路去做,就可以了
!
Date date = new Date();
date = s.parse("2007-06-06 15:15:00");
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT+8:00"));calendar.setTime(date);
long time = calendar.getTimeInMillis() / 1000;
如果在同一个月里可以实现如果一个是2007-06-06 15:15:00 2007-07-28 15:15:00就不管用了~~~~~~~~===============================
管用的啊。SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date d1 = sdf.parse("2007-06-06 15:15:00");
Date d2 = sdf.parse("2007-07-28 15:15:00");
System.out.println(d1.compareTo(d2)); //输出的值是“-1”,说明 d1 在 d2 之前。
System.out.println(d2.compareTo(d1)); //输出的值是“1”,说明 d2 在 d1 之后。
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