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 ()); } } |