Here you can find the source of getYearMonthList(int year)
Parameter | Description |
---|---|
year | which year's month will be return, if the year equals 0, return current year |
public static Date[] getYearMonthList(int year)
//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; } }