Name: avC70361 Date: 01/28/98
java.sql.Date instances created with constructor java.sql.Date(long millis) in
different time-zones with the same millis value are not equal. That is caused by
the fact that the constructor wipes time fields and then sets year, mounth and day
fields with values extracted from millis parameter using default TimeZone.
Therefore, when created in time-zones with different offsets, two java.sql.Date
instances are representing different points in time.
Here is the test demonstrating the bug:
--------------SQLDateTest.java-------------
import java.sql.Date;
import java.util.TimeZone;
public class SQLDateTest {
public static void main(String args[]) {
long date = 123456789L;
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
Date date1 = new Date(date);
System.out.println(new java.util.Date(date));
TimeZone.setDefault(TimeZone.getTimeZone("PST"));
Date date2 = new Date(date);
System.out.println(new java.util.Date(date));
if (date1.equals(date2)) {
System.out.println("Passed.");
} else {
System.out.println("Failed." + date1 + " != " + date2);
}
}
}
-----------------The test output-------------
> java SQLDateTest
Fri Jan 02 10:17:36 GMT+00:00 1970
Fri Jan 02 02:17:36 PST 1970
Failed.1970-01-02 != 1970-01-02
======================================================================