Date of Java

Source: Internet
Author: User

Date class
1.java.lang.system class
The public static long Currenttimemillis () provided by the system class is used to return the time difference in milliseconds between the current and January 1, 1970 0:0 0 seconds

2. Java.util.Date class: Indicates a specific moment, accurate to milliseconds
① Construction Method:
The date () object created using the parameterless construction method of the date class can get the local current time.
Date (long date)
② Common methods
GetTime (): Returns the number of milliseconds represented by this Date object since January 1, 1970 00:00:00 GMT.
ToString (): Converts this Date object to the following form of String:dow mon dd hh:mm:ss zzz yyyy
Where: Dow is a day of the week (Sun, Mon, Tue, Wed, Thu, Fri, Sat), ZZZ is the time standard.

Note: The API of the date class is not easy to internationalize, most of it is discarded,

3.java.text.simpledateformat class: is a specific class that formats and resolves dates in a way that is not related to the locale.
It allows formatting (date  text), parsing (text  date)
Formatting:
SimpleDateFormat (): Default schema and Locale creation object
Public SimpleDateFormat (String pattern): The construction method can create an object in the format specified by the parameter pattern, which invokes:
Public String Format (date date): Method format Time Object date
Analytical:
Public Date Parse (string source): Parses the text from the beginning of the given string to generate a date

4.java.util.calendar (Calendar) class
The calendar is an abstract base class that is used to perform the functions of interacting between date fields.
① how to get a calendar instance
Using the Calendar.getinstance () method
The constructor that invokes its subclass GregorianCalendar.
② Common methods
An instance of the calendar is an abstract representation of system time,
Use the Get (int field) method to get the time information you want. such as year, MONTH, Day_of_week, Hour_of_day, MINUTE, SECOND
public void Set (int field,int value)
public void Add (int field,int amount)
Public final Date GetTime ()
Public final void SetTime (date date)

Date of Java

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.