How many days are there before the last day of this month for java basic computing?

Source: Internet
Author: User

Calendar c = new GregorianCalendar (); // GregorianCalendar is a specific subclass of Calendar. It provides a standard Calendar system used by most countries/regions in the world.

GredorianCalendar is a hybrid calendar that allows callers to change the start date by calling setGregorianChange.

Calendar c = new Calendar. getInstance (TimeZone. getTimeZone ("GMT + 08: OO"); // This is the UTC + 8 time, that is, Beijing time.

Int year = c. get (Calendar. YEAR); // obtain the year

Int month = c. get (Calendar. MONTH) = 1; // obtain the current month. 0 indicates July

Int day = c. get (Calendar. DAY_OF_MONTH); // get the current day
Int first = c. getActualMinimum (c. DAY_OF_MONTH); // obtain the minimum number of days of the month
Int last = c. getActualMaximum (c. DAY_OF_MONTH); // obtain the maximum number of days of the month
Int time = c. get (Calendar. HOUR_OF_DAY); // get the current hour
Int min = c. get (Calendar. MINUTE); // get the current MINUTE
Int xx = c. get (Calendar. SECOND); // get the current SECOND



SimpleDateFormat s = new SimpleDateFormat ("yyyy-MM-dd HH: mm: ss ");

String curDate = s. format (c. getTime (); // the current date
System. out. println ("current time:" + year + "-" + month + "-" + day + "" + time + ":" + min + ":" + xx );
System. out. println ("first and last days:" + first + "," + last );

System. out. println ("current date curDate ===:" + curDate );

Output result:

Current Time: 22:50:54
First and last days:

Current date: 22:50:54




With the current number of days and the maximum number of days of the month, you can calculate the number of days remaining in the last day of the month.

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.