Java basics: Calendar class

Source: Internet
Author: User
Package day7; import java. util. calendar; import java. util. date;/*** java. util. the Calendar class * is recommended to use the Calendar class * For date and time processing. It is an abstract class and cannot be instantiated. use static Calendar getInstance () to obtain a Calendar Object * int get (int field ): returns the value of the specified Calendar field */public class CalendarDemo {public static void main (String [] args) {Calendar c = Calendar. getInstance (); int y = c. get (Calendar. YEAR); System. out. println (y); // 2013 Date time = c. getTime (); System. out. println (time); // Wed May 15 15:06:17 CST 2013 }}

Common static constants:

YEAR indicates the field number Of The YEAR.
MONTH indicates the number of the MONTH field. The MONTH range is [0, 11].
DATE indicates the day of a month.
DAY_OF_MONTH indicates the day of a month.
DAY_OF_WEEK indicates the day of the week.
HOUR_OF_DAY/HOUR indicates the HOUR
MINUTE indicates the MINUTE
SECOND indicates the SECOND

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.