Java Month getQuarterLastMonth(String quarter)

Here you can find the source of getQuarterLastMonth(String quarter)

Description

Determine the last month of each quarter based on quarter.

License

Open Source License

Parameter

Parameter Description
quarter quarter number

Return

String, the return value will be: yyyy03, yyyy06, yyyy09, yyyy12.

Declaration

public static String getQuarterLastMonth(String quarter) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from ww w . j ava 2s.  c  o m*/
     * Determine the last month of each quarter based on quarter.
     * 
     * <pre>
     * examples:
     * DateUtils.getLastMonth("201201") = "201203"
     * DateUtils.getLastMonth("201202") = "201206"
     * DateUtils.getLastMonth("201203") = "201209"
     * DateUtils.getLastMonth("201204") = "201212"
     * other conditions will return null.
     * </pre>
     * 
     * @param quarter quarter number
     * @return String, the return value will be: yyyy03, yyyy06, yyyy09, yyyy12.
     */
    public static String getQuarterLastMonth(String quarter) {
        if (null == quarter) {
            return null;
        }
        String year = quarter.substring(0, 4);
        String quart = quarter.substring(4, 6);
        String month = "";
        if (quart.equals("01")) {
            month = "03";
        } else if (quart.equals("02")) {
            month = "06";
        } else if (quart.equals("03")) {
            month = "09";
        } else if (quart.equals("04")) {
            month = "12";
        } else {
            return null;
        }
        return year + month;
    }
}

Related

  1. getMonthTotal(Double bsAmount, Double susAmount, Double changeRate)
  2. getNextMonth(String curYearMonth)
  3. getNextMonth(String month)
  4. getNextMonthSpe(String curYearMonth)
  5. getPreMonth(String thisMonth)
  6. getRSLILMonth(int month)
  7. getSecondByMonth(int month)
  8. getStatis_month()
  9. getTargetMonth(Integer targetYm)