The use and difference of six major time classes in Java

Source: Internet
Author: User

about the use and differences of six time classes in Javajava.util.Datejava.sql.Date java.sql.Time java.sql.Timestamp Java.text.SimpleDateFormatJava.util.Calendar

Java.util.Date date format is: Month Day time minutes seconds
Java.sql.Date Date format: day of month
Java.sql.Time date format: hours and seconds
Java.sql.Timestamp Date format: Day of the month and seconds (nanosecond)

The dates taken from the database are generally used with the Gettimestamp () method, such as a field data type in Oracle date, and the Gettimestamp () method to obtain an accurate date.

Java.util.Calendar Class (Calendar Class) The Calendar class is an abstract base class used primarily for various calculations between dates to get a calendar instance: using the Calendar.getinstance () method or a constructor that calls its subclass GregorianCalendar.

Java.text.SimpleDateFormat: Five other types of time that can be formatted with the same style

----------------------------------------------------------------------------

Java.util.Date is the parent class of Java.sqldate,time,timestamp

1.java.util.date is used in cases other than SQL statements. 2.java.sql.date is used for SQL statements, new Java.sql.Date (New Java.util.Date (). GetTime (), which contains only dates and no time parts3. It has a gettime method to return the number of milliseconds---------------------------------------------------------------------------------------------4. Converting to each otherNew Java.sql.Date (New Java.util.Date (). GetTime ())New Java.util.Date (new Java.sql.Date (0). GetTime ())Use of 5.java.sql.timestamp6.java.sql.time 7.java.util.calendar8. All time dates can be SimpleDateFormat formatted format ()

The use and difference of six major time classes in Java

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.