Here you can find the source of getMonth(int week, int year)
Parameter | Description |
---|---|
week | the week |
year | the year |
public static int getMonth(int week, int year)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; public class Main { /**//from w ww.j av a2 s . c o m * Gets the month. * * @param week the week * @param year the year * * @return the month */ public static int getMonth(int week, int year) { Calendar cal = getFirstSundayDateInYear(year); cal.add(Calendar.DAY_OF_YEAR, (week - 1) * 7); return cal.get(Calendar.MONTH); } /** * Gets the first sunday date in year. * * @param year the year * * @return the first sunday date in year */ public static Calendar getFirstSundayDateInYear(int year) { Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, year); cal.set(Calendar.DAY_OF_YEAR, 8); if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) cal.set(Calendar.DAY_OF_YEAR, 7); int daydiff = cal.get(Calendar.DAY_OF_WEEK) - Calendar.SUNDAY; cal.add(Calendar.DATE, daydiff * -1); return cal; } }