Date usage in Java

Source: Internet
Author: User
Tags dateformat
How to Use the date in Java-general Linux technology-Linux programming and kernel information. The following is a detailed description. Due to the needs of the company's project, I specially studied the classes and methods for processing dates in Java. The summary is as follows for your reference. If you have any problems, please let me know.

In Java, Date Processing classes mainly include Date, Calendar, and DateFormat. in JDK, their corresponding package location and related Derived classes are as follows:
1. Date: java. util. Date;
2. Calendar: abstract class java. text. DateFormat. A subclass of this class is java. text. SimpleDateFormat.
3. DateFormat: abstract class java. util. Calendar. A subclass derived from this class is java. util. GregorianCalendar.
(Note: If you are not familiar with specific classes and abstract classes, you can refer to the relevant Java materials)

The preceding three types are analyzed as follows:

I. Analysis of the Date class

The Date class evolved from JDK 1.0. At that time, it only contained several simple methods to process Date data. Due to the poor practicability of these methods, they are basically replaced by methods in the Calendar class. This improvement aims to better process date data in an international format. The Date class is actually only a package class. It contains a long integer data that represents the number of milliseconds that have elapsed since GMT (Greenwich Mean Time), January 1, 1970 00:00:00, January 1, January 1, or later.

To better understand the Date class, the following simple example is provided to illustrate the use of Date:
CODE: import java. util. Date;
Public class DateTest1 {
Public static void main (String [] args ){
/** Get the system Date **/
Date date = new Date ();
System. out. println (date. 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.