Re: Convert java.util.Date to java.sql.Date



Bumsys@xxxxxxxxx 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
.



Relevant Pages

  • Re: Migration of Teradata and DB2 Timestamp fields.
    ... There is no datatype in SQL Server that has a precision of 1 millisecond. ... - Store the timestamp in a CHARcolumn in format ... Note that the precision will go back to 3.33 milliseconds when you ...
    (microsoft.public.sqlserver.datawarehouse)
  • Re: "HH:mm:ss" string to long ?
    ... > I have a timestamp in HH:mm:ss format, in a String object, that I'd ... > Epoch. ... darrell dot grainger at utoronto dot ca ...
    (comp.lang.java.help)
  • Re: Extracting milliseconds from a time field
    ... component of the timestamp, eg in this case 679 in cell B. ... NOWis indeed milliseconds, not less. ... limited precision arithmetic when applied to decimal values. ...
    (microsoft.public.excel)
  • Re: Generating serial numbers
    ... need to allocate unique names to them. ... distinguish between transactions that arrive a few tens of milliseconds ... So the timestamp would be quite long. ... (such as base64, as made simple with the Math::BaseCnv module that Uri ...
    (comp.lang.perl.misc)
  • Re: Simple date compare
    ... get the timestamp long, and divide by the number of milliseconds in ... Calendar lets one zero out the time fields, leaving only the date fields filled. ... That's going to be a lot less code and a lot more direct than messing with milliseconds and timezone calculations. ...
    (comp.lang.java.programmer)