Java (Time, Imestamp, data) conversion

Source: Internet
Author: User

1 The time type in Java java.sql the three database-related datetime types under the package, respectively:?    Date: Represents a day, only a month or so, no time or seconds. will lose time;?    Time: The hour, day and minute;     ----Date getTime ()
2The conversion of time types to the java.util.Date of the three time types of the database is basically not necessary because this is a reference to the parent class object, and no conversion is required. Java.sql.Date Date=... java.util.Date d=Date;java.sql.time Time=... java.util.Date d=Time;java.sql.timestamp Timestamp=... java.util.Date d=timestamp; When you need to convert a java.util.Date into a database of three time types, this cannot be directly assigned, which requires the use of a constructor of three time types for the database. The constructors for the date, time, and timestamp three classes under the Java.sql package require a long parameter representing the millisecond value. Creating these three types of objects requires only a millisecond value. We know that Java.util.Date has the gettime () method to get the millisecond value, then this conversion is not a problem. Java.utl.Date D=Newjava.util.Date (); Java.sql.Date Date=NewJava.sql.Date (D.gettime ());//will lose secondsTime time =NewTime (D.gettime ()); Timestamp Timestamp=NewTimestamp (D.gettime ());

Java (Time, Imestamp, data) conversion

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.