Here you can find the source of getSundayDate(int week, int year)
Parameter | Description |
---|---|
week | the week |
year | the year |
public static java.util.Date getSundayDate(int week, int year)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; public class Main { /**/* w w w. j a v a 2 s . c o m*/ * Gets the sunday date. * * @param week the week * @param year the year * * @return the sunday date */ public static java.util.Date getSundayDate(int week, int year) { Calendar cal = getFirstSundayDateInYear(year); cal.add(Calendar.DAY_OF_YEAR, (week - 1) * 7); return cal.getTime(); } /** * 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; } }