Java Month of Year getPrevMonth(String divisionDate, int day, String outputFormat)

Here you can find the source of getPrevMonth(String divisionDate, int day, String outputFormat)

Description

get Prev Month

License

Open Source License

Declaration

public static String getPrevMonth(String divisionDate, int day, String outputFormat) throws Exception 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Calendar;

import java.util.Locale;

public class Main {
    public static String getPrevMonth(String divisionDate, int day, String outputFormat) throws Exception {
        Calendar cal = Calendar.getInstance();
        cal.set(cal.YEAR, Integer.parseInt(divisionDate.substring(0, 4)));
        cal.set(cal.MONTH, Integer.parseInt(divisionDate.substring(4, 6)) - 1);
        cal.set(cal.DATE, Integer.parseInt(divisionDate.substring(6, 8)));

        cal.add(cal.MONTH, day);// ww w.j a v  a 2  s  .  c o m

        Locale locale = new Locale("KOREAN", "KOREA");

        SimpleDateFormat formatter = new SimpleDateFormat(outputFormat, locale);
        return formatter.format(cal.getTime());
    }
}

Related

  1. getNrDaysOfMonth(int month, int year)
  2. getNumberOfDays(int year, int month)
  3. getOntologyURIBase(String defaultBase, boolean appendYear, boolean appendMonth, boolean appendDay)
  4. getPreviousDateStringByMonth(int months)
  5. getPreviousDay(int year, int month, int day, int days)
  6. getPreYearMonth()
  7. getSecondsOfMonth(int year, int month)
  8. getStartAndEndOfMonth(int month, int year)
  9. getStrDayOfWeek(int _year, int _month, int _day)