Re: Convert java.util.Date to java.sql.Date
Bumsys@gmail.com wrote:
when I convert java.util.Date to java.sql.Date I want to get sqlDate
in formate "dd-mm-yyyy hh:mm a"???
java.sql.Date does not *have* "formats". As I mentioned, it only stores
milliseconds since epoch. That means it already contains the time down to the
millisecond.
Review my recommendation about java.text.DateFormat. Did you consider the
information I provided upthread?
GArlington mentioned java.sql.Timestamp. Aside from its more natural match to
the SQL TIMESTAMP type, Timestamp holds time to nanosecond resolution. Just
like java.util.Date and its other offspring, java.sql.Date, Timestamp also
does not have a "format" regarding "hh:mm", etc.
Sidebar: The Javadocs refer to the "precision of a Timestamp object" in terms
of the number of characters in its String representation. That is bogus.
Like its parent, java.util.Date, Timestamp holds long values that represent
milliseconds (actually seconds) and nanoseconds since epoch. Its precision
therefore is nanoseconds. I don't know what they were thinking when they
wrote that part about "precision" being "19" - not even any units specified.
Much as I am in favor of the Javadocs, occasionally they disappoint.
Anyway, OP, for your purposes remember that java.util.Date and its offspring
DO NOT HAVE FORMATS for the date. The only "format" they have is one or two
long values.
Please review the advice given earlier.
--
Lew