Calendar to get the month and the day, seconds, milliseconds

Source: Internet
Author: User

Reproduced from the Internet, to be backed up

Start using the new Date () test and get it through Date.getmonth (), and Date.getday (), but later found out that the two jdk1.1 versions of the interview are not now, and the results are incorrect. int month = (Date.get (calendar.month)) +1;
int day = Date.get (calendar.day_of_month);

Get the current month and date

Tried it, and it was right.

Later, I looked at the Java Doc Document and the month field explained the following

Field number for Get and set indicating the month. This is a calendar-specific value. The "the" the "the" is January which is 0; The last depends on the number of months in a.

The value of this field is only a property field value that describes get () to obtain the month

The following are for obtaining other:

Calendar CD = Calendar.getinstance ();
int YY = Cd.get (calendar.year);
int MM = Cd.get (calendar.month) +1;
int DD = Cd.get (calendar.date);
int HH = Cd.get (Calendar.hour);
int NN = Cd.get (Calendar.minute);
int SS = Cd.get (Calendar.second);
int MI = Cd.get (Calendar.millisecond);

Calendar cal = Calendar.getinstance ();

When the year before last
int year = Cal.get (calendar.year);
Current month
int month = (Cal.get (calendar.month)) +1;
Days of the current month: current day
int day_of_month = Cal.get (calendar.day_of_month);
Current time: hour_of_day-24-hour system; HOUR-12-hour system
int hour = Cal.get (Calendar.hour_of_day);
Current score
int minute = Cal.get (Calendar.minute);
Current seconds
int second = Cal.get (Calendar.second);
0-a.m.; 1-PM
int ampm = Cal.get (CALENDAR.AM_PM);
The week ordinal of the current year
int week_of_year = Cal.get (calendar.week_of_year);
The week ordinal of the current month
int week_of_month = Cal.get (calendar.week_of_month);
The day ordinal of the current year
int day_of_year = Cal.get (calendar.day_of_year);

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.