*UPDATE*我的类 java.util.Date shippingDate
中有一个实例,我需要比较它是否等于当前日期。
java.util.Date shippingDate ;
Calendar g = new GregorianCalendar();
shippingDate=g.getTime();
if(shippingDate.equals(new Date()))
{
System.out.println("Match found");
}
Equals
在 Date 中被覆盖,所以它应该执行 sysout。但它不打印任何东西。
PS#我不允许使用 Joda Time 库。
更新- 是否有任何其他方法可以将 shippingDate
与当前日期进行比较。我不想使用 SimpleDateFormat
对当前日期进行硬编码。它必须从系统生成。
最佳答案
Javadoc给出一个线索(强调我的):
public Date()
Allocates a
Date
object and initializes it so that it represents the time at which it was allocated, measured to the nearest millisecond.
关于java - 在java中使用equals比较日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19337609/