Java Month Get getMonthByNow(int month)

Here you can find the source of getMonthByNow(int month)

Description

get Month By Now

License

Apache License

Declaration

public static Date getMonthByNow(int month) 

Method Source Code


//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;
    }
}

Related

  1. getMonthAdd(String operateDate, int flag)
  2. getMonthAndDate()
  3. getMonthBefore(Date d, int number)
  4. getMonthBegin(String strdate)
  5. getMonthBegin(String strdate)
  6. getMonthCount(String from, String to)
  7. getMonthDesc(Date month)
  8. getMonthEnd(Date date)
  9. getMonthEnd(String strdate)