Java Year Month getYearMonthList(int year)

Here you can find the source of getYearMonthList(int year)

Description

return array including 12 months of one year

License

Open Source License

Parameter

Parameter Description
year which year's month will be return, if the year equals 0, return current year

Declaration

public static Date[] getYearMonthList(int year) 

Method Source Code

//package com.java2s;

import java.util.Calendar;
import java.util.Date;

public class Main {
    /**/*  w ww  .j  av  a  2s  .co m*/
     * return array including 12 months of one year
     *
     * @param year
     *            which year's month will be return, if the year equals 0,
     *            return current year
     * @return
     */
    public static Date[] getYearMonthList(int year) {
        Calendar cal = Calendar.getInstance();
        if (year > 0)
            cal.set(Calendar.YEAR, year);
        cal.set(Calendar.DAY_OF_MONTH, 1);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);

        Date[] d = new Date[12];
        for (int i = 0; i < 12; i++) {
            Calendar c = (Calendar) cal.clone();
            c.set(Calendar.MONTH, i);
            d[i] = c.getTime();
        }
        return d;
    }
}

Related

  1. getYearMonthDate()
  2. getYearMonthDateByMisSecond(long misSecond)
  3. getYearMonthDay()
  4. getYearMonthDay(Date date)
  5. getYearMonthDay(final int year, final int month, final int day)
  6. getYearMonths(List time)
  7. getYearMonthStr(Date parseDate)
  8. getYearMonthString(Date date)
  9. lastDay(int year, int month)