Here you can find the source of getMonthByNow(int month)
public static Date getMonthByNow(int month)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static Date getMonthByNow(int month) { SimpleDateFormat simpleDateFormatMM = new SimpleDateFormat("yyyy-MM"); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Calendar c = Calendar.getInstance(); c.setTime(new Date()); c.add(Calendar.MONTH, month); Date mb = c.getTime();/*ww w .j av a2 s. co m*/ String mon = simpleDateFormatMM.format(mb); StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(mon).append("-06 0:0:0"); System.out.println(stringBuffer.toString()); Date date = null; try { date = simpleDateFormat.parse(stringBuffer.toString()); } catch (ParseException e) { e.printStackTrace(); } return date; } }