Java Month Get getMonthOfSeason(Date date, boolean firstOrLast)

Here you can find the source of getMonthOfSeason(Date date, boolean firstOrLast)

Description

get Month Of Season

License

Apache License

Declaration

public static String getMonthOfSeason(Date date, boolean firstOrLast) 

Method Source Code

//package com.java2s;
/**/*from   w ww .j  a v  a  2  s .  c o m*/
 * Copyright 1996-2013 Founder International Co.,Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * @author kenshin
 */

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static String getMonthOfSeason(Date date, boolean firstOrLast) {
        SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy");
        SimpleDateFormat monthFormat = new SimpleDateFormat("MM");
        String yearStr = yearFormat.format(date);
        String monthStr = monthFormat.format(date);
        int month = Integer.parseInt(monthStr);

        String array[][] = { { "01", "02", "03" }, { "04", "05", "06" }, { "07", "08", "09" },
                { "10", "11", "12" } };

        int season = 1;

        if (month >= 1 && month <= 3) {
            season = 1;
        }
        if (month >= 4 && month <= 6) {
            season = 2;
        }
        if (month >= 7 && month <= 9) {
            season = 3;
        }
        if (month >= 10 && month <= 12) {
            season = 4;
        }

        String start_month = array[season - 1][0];
        String end_month = array[season - 1][2];

        if (firstOrLast) {
            return yearStr + start_month;
        } else {
            return yearStr + end_month;
        }
    }
}

Related

  1. getMonthForString(String monthStr, Locale locale)
  2. getMonthInfo(int monthInfo)
  3. getMonthLength(String countDate)
  4. getMonthNo(Date date)
  5. getMonthNumber()
  6. getMonthPath(Date date)
  7. getMonthRange(String strBeginDate, String strEndDate, String pattern)
  8. getMonths()
  9. getMonths(DateFormatSymbols symbols)