Java Month Get getMonthAdd(String operateDate, int flag)

Here you can find the source of getMonthAdd(String operateDate, int flag)

Description

get Month Add

License

Apache License

Declaration

public static String getMonthAdd(String operateDate, int flag) throws ParseException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Main {

    public static String getMonthAdd(String operateDate, int flag) throws ParseException {
        if (operateDate.length() == 7) {
            operateDate = operateDate + "-01";
        }/*www  .j a  v a 2s . c  om*/
        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c1 = Calendar.getInstance();
        c1.setTime(sdf.parse(operateDate));
        c1.add(Calendar.MONTH, flag);
        return sdf.format(c1.getTime()).substring(0, 7);
    }
}

Related

  1. getMonth(String str_date)
  2. getMonth(String strDate)
  3. getMonth(String strDate)
  4. getMonth(String tempdat, Locale locale)
  5. getMonth1D()
  6. getMonthAndDate()
  7. getMonthBefore(Date d, int number)
  8. getMonthBegin(String strdate)
  9. getMonthBegin(String strdate)