Java date related class examples

1、 Date class

Class date represents a specific moment, accurate to milliseconds. The number of milliseconds (long) from 00:00:00 on January 1, 1970 is used to represent a specific point in time, which can be positive or negative.

Many methods in the date class are outdated, and calendar is used instead.

Common methods are

long getTime() void setTime(long time)

2、 Simpledateformat

Simpledateformat converts between date and string according to a specific date format

common method

String format (date): converts a date into a string in the specified format. Date parse (string STR): converts a string into a date in the specified format

Characters that can be used to specify the format

3、 Calendar

java. util. Calendar is an abstract class, which is mainly used to calculate the time component.

common method

(1) Conversion between date and calendar

(2) Getinstance() method

Calendar is an abstract class that provides a factory method: calendar getinstance() to get an instance of the calendar type

(3) Get (int field) method to get the time component

(4) The set() method sets the time component

(5) The add () method modifies the time component based on the current time component

(6) Getactualmaximum() gets the maximum value allowed for a time component

4、 A comprehensive example of date, simpledateformat, and calendar

summary

The above is all about the detailed explanation of Java date related class examples in this paper. I hope it will be helpful to you. Interested friends can continue to refer to this site: detailed explanation of basic date class code of java development, examples of time and timestamp mutual conversion realized by Java programming, etc. if there are deficiencies, please leave a message and point out. Thank you for your support!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>