Program:
Import Java.util.Calendar;
/**
* @author ZW
* Find a way to get the first and last day of the month
*/
public class Firstendofmonth {
Private Calendar C = calendar.getinstance ();
Public String getfirstdayofmonth (int syear,int smonth) {
String tstartdate = "";
C.set (c.year,syear);
C.set (C.month,smonth);
Tstartdate = string.valueof (syear) + "-" +string.valueof (smonth) + "-" +c.getactualminimum (C.day_of_month);
return tstartdate;
}
Public String getenddayofmonth (int syear,int smonth) {
String tenddate = "";
C.set (c.year,syear);
C.set (C.month,smonth);
Tenddate = string.valueof (syear) + "-" +string.valueof (smonth) + "-" +c.getactualmaximum (C.day_of_month);
return tenddate;
}
/**
* @param args
*/
public static void Main (string[] args) {
Firstendofmonth tfirstendofmonth = new Firstendofmonth ();
System.out.println ("2010 10 First day:" +tfirstendofmonth.getfirstdayofmonth (2010, 10));
System.out.println ("2010 10 Last Day:" +tfirstendofmonth.getenddayofmonth (2010, 10));
}
Implementation results: 2010 10 First day: 2010-10-1 2010 10 Last day: 2010-10-30