According to this, I should always get a date in this format when I call toString:
dow mon dd hh:mm:ss zzz yyyy
Sometimes I get this format on Linux RHEL 3 (yeah I know that is REALLY OLD but I cannot update) using Java 1.6.
yyyy mon dd hh:mm:ss.xxxx
Saving the date to an H2 database via hiberante/spring and reading it back again seams to change the format that is produced by java.util.Date.toString().
If I populate a date d1 with java.util.Calendar.getTime() and I save d1 to a H2 database and read it back into a second date object d2 I make the following observations:
(1) d1.toString() produces the dow mon dd hh:mm:ss zzz yyyy format
(2) d2.toString() produces yyy mo dd hh:mm:ss.xxx and this is contrary to the documentation!
(2) assertTrue(d1.equals(d2)) fails.
(3) If I extract the year, month, day, hour, minute, second from cal1 and cal2 where cal1 and cal2 are populated from d1 and d2 via Calendar.setTime, the year, month day, hour, minute, seconds match!
Your link goes to the documentation for Java 1.4.2, but I doubt anything has changed here in later Java versions.
But if you're relying on how java.util.Date() converts itself to a string in its toString() method to store a date in the database, then you're doing something wrong.
Why are you trying to store a Date object as a string in the database? Doesn't the database have a DATE, DATETIME or TIMESTAMP column type?
If you for some reason still want to store it as a string, use a java.text.SimpleDateFormat object to convert the Date object to and from a string; SimpleDateFormat allows to to exactly specify the format.