G
grz01
Hi there,
(Again) Im trying to understand the EXACT difference between
java.util.Date vs java.sql.Date.
Googling, I can see that this is a very "popular" subject, but I still
cannot figure out it exactly.
Many writers claim that java.sql.Date only stores the DATE part (yyyy-
mm-dd) but not the TIME part (hh:MM:ss) of a Date/Time value, but that
I can easily disprove:
java.util.Date ud = new java.util.Date();
java.sql.Date sd = new java.sql.Date(ud.getTime());
System.out.println(DateFormatUtils.format(ud, "yyyy-mm-dd
hh:MM:ss.SSS"));
System.out.println(DateFormatUtils.format(sd, "yyyy-mm-dd
hh:MM:ss.SSS"));
Output:
2009-17-18 03:09:36.635
2009-17-18 03:09:36.635
So, apparently, java.sql.Date and java.util.Date have THE SAME
precision (at least down to the millisecs...).
And the official API documentation, really looks more confusing than
helpful to me::
"java.sql.Date:
A thin wrapper around a millisecond value that allows JDBC to identify
this as an SQL DATE value. A milliseconds value represents the
number of milliseconds that have passed since January 1, 1970
00:00:00.000 GMT.
To conform with the definition of SQL DATE, the millisecond values
wrapped by a java.sql.Date instance must be 'normalized' by setting
the hours, minutes, seconds, and milliseconds to zero in the
particular time zone with which the instance is associated. "
Exactly what means "an SQL DATE value" ? How EXACTLY does it differ
from a java.util.Date value?
Most importantly: WHY does JDBC *need* to distinguish between them?
And, here again: "a java.sql.Date instance must be 'normalized' by
setting the hours, minutes, seconds, and milliseconds to zero in the
particular time zone..."
What does that mean exactly? Apparently, the constructor doesnt
enforce this restriction, per the example above. So what's the REAL
point with this type, java.sql.Date?
Very greatful, if you can help me clarify this, once and for all.
TIA / grz01
(Again) Im trying to understand the EXACT difference between
java.util.Date vs java.sql.Date.
Googling, I can see that this is a very "popular" subject, but I still
cannot figure out it exactly.
Many writers claim that java.sql.Date only stores the DATE part (yyyy-
mm-dd) but not the TIME part (hh:MM:ss) of a Date/Time value, but that
I can easily disprove:
java.util.Date ud = new java.util.Date();
java.sql.Date sd = new java.sql.Date(ud.getTime());
System.out.println(DateFormatUtils.format(ud, "yyyy-mm-dd
hh:MM:ss.SSS"));
System.out.println(DateFormatUtils.format(sd, "yyyy-mm-dd
hh:MM:ss.SSS"));
Output:
2009-17-18 03:09:36.635
2009-17-18 03:09:36.635
So, apparently, java.sql.Date and java.util.Date have THE SAME
precision (at least down to the millisecs...).
And the official API documentation, really looks more confusing than
helpful to me::
"java.sql.Date:
A thin wrapper around a millisecond value that allows JDBC to identify
this as an SQL DATE value. A milliseconds value represents the
number of milliseconds that have passed since January 1, 1970
00:00:00.000 GMT.
To conform with the definition of SQL DATE, the millisecond values
wrapped by a java.sql.Date instance must be 'normalized' by setting
the hours, minutes, seconds, and milliseconds to zero in the
particular time zone with which the instance is associated. "
Exactly what means "an SQL DATE value" ? How EXACTLY does it differ
from a java.util.Date value?
Most importantly: WHY does JDBC *need* to distinguish between them?
And, here again: "a java.sql.Date instance must be 'normalized' by
setting the hours, minutes, seconds, and milliseconds to zero in the
particular time zone..."
What does that mean exactly? Apparently, the constructor doesnt
enforce this restriction, per the example above. So what's the REAL
point with this type, java.sql.Date?
Very greatful, if you can help me clarify this, once and for all.
TIA / grz01