Java. util. Date and Java. util. Date, java. SQL. Timestamp

Source: Internet
Author: User

Java. util. Date: indicates the operation time:

Java. util. Date d1 = new java. util. Date (); // a time is created based on the current time.

Of course, you can also use another method: long times =System. currenttimemillis ();

Java. util. Date D2 = new date (times );

 

Java. SQL. Date: used when interacting with the database.

However, java. SQL. date is only accurate to days. That is, only (year-month-day)

Java. SQL. Date SD = new java. SQL. Date (d1.gettime ());

Or:

Java. SQL. Date SD = new java. SQL. Date (system. currenttimemillis ());

If you use Java. SQL. date to insert a database, it will not be accurate to time.

Paramentedstatement. setdate (SD); // It is only accurate to the day. If the time is not accurate, there is no problem.

 

If this does not meet the requirements. You can use Java. SQL. timestamp. This can be accurate to milliseconds. That is, (year-month-day hour: minute: Second. millisecond)

Paramentedstatement. settimestamp (New java. SQL. timestamp (SD. gettime ()));

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.