"Things You Don't Know series" class for working with dates in Java

Source: Internet
Author: User

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

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.