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.