Java 7 java.util.Date vs java.sql.Date problem
Hello everybody, I'm having serious problem with the java 7 version Date api. When I try to convert the java.sql.Date to java.util.Date the date is always different of two days. For example in database I have date 2011-11-08, I read it into java.sql.Date and when I try to convert it into java.util.Date - the date is 2011-11-06. I tried following:
new java.util.Date(<java.sql.Date variable>.getTime())
SimpleDateFormat sqlFormat = new SimpleDateFormat("yyyy-MM-dd");
and all of this returns the wrong date. The java.util.Date JavaDoc for Java 7 says following: "Although the Date class is intended to reflect coordinated universal time (UTC), it may not do so exactly, depending on the host environment of the Java Virtual Machine. Nearly all modern operating systems assume that 1 day = 24 × 60 × 60 = 86400 seconds in all cases. In UTC, however, about once every year or two there is an extra second, called a "leap second." The leap second is always added as the last second of the day, and always on December 31 or June 30. For example, the last minute of the year 1995 was 61 seconds long, thanks to an added leap second. Most computer clocks are not accurate enough to be able to reflect the leap-second distinction."
So my question is: could the problem be that java.util.Date in java 7 uses in the long representation of date (the number of milliseconds since epoch) these "leap seconds" but the java.sql.Date does not? Is there any way to correct this behavior? Thanks a lot!
EDIT> I have found out, that the java.sql.Date to java.util.Date is correct - the problem is in the database fetch, where I'm getting the wrong java.sql.Date object in resultSet.getDate() method.