I'm unable to understand the documentation for java.sql.date
I'm wrestling with the issue of time zones across SQL, jdbc, JVM and linux.
I can see that the class I need to hand to / get from jdbc is java.sql.date. So I read the documentation, and can't make ANYTHING of it.
As I understand it, both java.util.Data and java.sql.date hold a number of milliseconds since the epoch.
When I look at the definition for the constructor for java.sql.date it says
"Constructs a Date object using the given milliseconds time value. If the given milliseconds value contains time information, the driver will set the time components to the time in the default time zone (the time zone of the Java virtual machine running the application) that corresponds to zero GMT."
OK - question 1 - what can be the meaning of "If the given milliseconds value contains time information" - clearly it contains SOME time information !!!
Do they mean "if the number of milliseconds you give the routine doesn't represent an exact day boundary, taking into account leap seconds etc. etc " ?? That sounds a fairly random test to meet/fail !
Or do they mean " for Heaven's sake give us something near mid-day, and we'll truncate it to the beginning of the day in question ?
question 2 - what, in words, is this strange clause "FOR" ?? It is clearly behaviour that is intended to make some gears mesh properly - but what gears ARE they?
java.sql.Date
, java.sql.Time
and java.sql.Timestamp
all extend java.util.Date
, however:
java.sql.Date
has milliseconds rounded to midnight - it's a "date with zero time" java.sql.Time
has milliseconds less than 24 hours - it's like a java.util.Date
on 1970-01-01
java.sql.Timestamp
has full Date and Time - like a regular java.util.Date
If I was you, I would avoid using the millisecond constructor. Instead, use Date.valueOf
.
java.sql.Date represents only the date, without any time information in it. java.sql.Time should be used for the time.
链接地址: http://www.djcxy.com/p/18520.html