fork(35) download
  1. import java.util.Calendar;
  2. import java.util.Date;
  3.  
  4. public class Main{
  5.  
  6. public static void main(String ar[]){
  7. Calendar cal = Calendar.getInstance();
  8. cal.add(Calendar.MONTH, -1);
  9. cal.set(Calendar.DATE, 1);
  10. Date firstDateOfPreviousMonth = cal.getTime();
  11. System.out.println(firstDateOfPreviousMonth );
  12. cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));
  13.  
  14. Date lastDateOfPreviousMonth = cal.getTime();
  15. System.out.println(lastDateOfPreviousMonth );
  16.  
  17. }
  18. }
Success #stdin #stdout 0.05s 246080KB
stdin
Standard input is empty
stdout
Sun Apr 01 06:25:53 GMT 2012
Mon Apr 30 06:25:53 GMT 2012