Here you can find the source of getWeekNumber()
public static int getWeekNumber()
//package com.java2s; //License from project: Open Source License import java.sql.Date; import java.util.Calendar; public class Main { /**/*w ww. j av a 2s . c o m*/ * Gets the week number. * * @return the week number */ public static int getWeekNumber() { return (getLastSundayDate().get(Calendar.DAY_OF_YEAR) - getFirstSundayDateInYear( 2009).get(Calendar.DAY_OF_YEAR)) / 7 + 1; } /** * Gets the last sunday date. * * @return the last sunday date */ public static Calendar getLastSundayDate() { Calendar cal = Calendar.getInstance(); int daydiff = cal.get(Calendar.DAY_OF_WEEK) - Calendar.SUNDAY; cal.add(Calendar.DATE, daydiff * -1); return cal; } /** * Gets the last sunday date. * * @param d the d * * @return the last sunday date */ public static Calendar getLastSundayDate(Date d) { Calendar cal = Calendar.getInstance(); cal.setTime(d); int daydiff = cal.get(Calendar.DAY_OF_WEEK) - Calendar.SUNDAY; cal.add(Calendar.DATE, daydiff * -1); return cal; } /** * 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; } }