Basic usage about DATE and Calendar classes

xiaoxiao2021-03-06  34

Date and Calendar are classes that provide time processes in the Java class library. Since the date is a very important status in commercial logic applications, it is necessary to conduct a basic explanation of these two classes. If you don't, please correct it. Date Class For the name, see if the class is related to the date, the most important role of this class is to get the current time, however this class also has set time and some other functions, but due to its own design, these The method has been criticized, and these criticisms have been transplanted to another class, which is the second class Calendar that is going to say today. Before talking about two classes, you can't mention a class here, that is, the DateFormat class, this class is used to format the date, will also speak later. First, let's take a look at an example of obtaining the current time: Date Date = New Date (); system.out.println; because I am more lazy, write some main sentences, above The statement first creates a target of Date, then use the GetTime method to get the current time, but pay attention, the result after the output does have a series of long integer numbers, why? In fact, this is the number of LONG types calculated according to the current time. As for how it is calculated, it is not described in this article, and how do you display the correct time? This is to use the DateFormat class above. This class is a base class. It has a subclass is SimpleDateFormat. Please see the following code: Date Date = new Date (); SimpleDateFormat Datefm = New SimpleDateFormat ("Eeee -Mmmm-dd-yyyy "; system.out.println; this code starts to create a Date object, used to get the current time, and the focus is the back SimpleDateFormat object, this Inheriting DateFormat, using the Format method to format the DATE object, then output, and the format customization is customized by the user, Eeee represents the month, and the DD representative day, YYYY represents the year. Using this method can perform output time according to user-defined format.

转载请注明原文地址:https://www.9cbs.com/read-63857.html

New Post(0)