JAVA get the first day and the last day of the month

// Get the first day of the month

= Calendar.getInstance Calendar Calendar (); 
Calendar.add (of the Calendar.MONTH, 0);
calendar.set (Calendar.DAY_OF_MONTH, 1);
return calendar.getTime ();

// get the last day of the month
= Calendar.getInstance Calendar Calendar (); 
Calendar.add (the Calendar.MONTH,. 1);
calendar.set (Calendar.DAY_OF_MONTH, 0);

// Get the first day of the last month
= Calendar.getInstance Calendar Calendar (); 
calendar.set (Calendar.MONDAY,, Calendar.get (Calendar.MONDAY,) - 1);
calendar.set (Calendar.DAY_OF_MONTH, 1);

// get the last day of the month
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MONDAY, calendar.get(Calendar.MONDAY) - 1);
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));

Guess you like

Origin www.cnblogs.com/yyhhblog/p/12050562.html