Java provides a series of classes for working with date and time, including creation date, time object, getting system current date, time, etc.
Date class:
Located in Java.util.Date, it exists from the JDK1.0, but now most of its constructors, methods are obsolete and are no longer recommended for use.
Here are the main characters of our article:
Calendar class:
Abstract class that implements a serialized interface for representing the calendar. Creating a Calendar object can be obtained through several static getinstance () methods.
Calendar and date are tool classes that represent dates, and they are freely convertible, with the following code:
Calendar calendar = calendar.getinstance ();D ate Date = Calendar.gettime (); Calendar calendar2 = Calendar.getinstance (); Calendar2.settime (date);
The Calendar class provides a number of ways to access, modify, and use date-time methods:
void Add (int field, int amount); Modify the rules for the calendar to add or subtract the specified amount of time int get (int field) for the given calendar field; Returns the value of the specified calendar field int getactualmaximum (int field); Returns the maximum value that a specified calendar field might have. For example, the maximum value for the month is 11int getactualmininum (int field); Returns the minimum value that a specified calendar field might have. For example, the minimum value for the month is 0void roll (int field, int amount); Similar to the Add () method, the difference is that when a amount exceeds the maximum range that the field can represent, it does not carry the void set (int field, int value) up one field; Sets the given Calendar field to the given value void set (int year, int month, int date); Sets the value of the calendar object's year, month, and Day 3 fields to void set (int year, int month, int date, int hourofday, int minute, int second)://Set Calendar object's years , month, day, time, minute, second 6 field values
"Things You Don't Know series" class for working with dates in Java