fork(3) download
  1. import java.time.*;
  2. import java.time.format.*;
  3.  
  4. class Ideone
  5. {
  6. public static void main (String[] args)
  7. {
  8. YearMonth thisMonth = YearMonth.now();
  9. YearMonth lastMonth = thisMonth.minusMonths(1);
  10. YearMonth twoMonthsAgo = thisMonth.minusMonths(2);
  11.  
  12. DateTimeFormatter monthYearFormatter = DateTimeFormatter.ofPattern("MMMM yyyy");
  13.  
  14. System.out.printf(" Today: %s\n", thisMonth.format(monthYearFormatter));
  15. System.out.printf(" Last Month: %s\n", lastMonth.format(monthYearFormatter));
  16. System.out.printf("Two Months Ago: %s\n", twoMonthsAgo.format(monthYearFormatter));
  17. }
  18. }
Success #stdin #stdout 0.3s 321728KB
stdin
Standard input is empty
stdout
         Today: September 2015
    Last Month: August 2015
Two Months Ago: July 2015