Here you can find the source of weekOfYear(Date date)
public static String weekOfYear(Date date)
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { public static String weekOfYear(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date);//from w w w . j av a 2 s .c o m int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day = cal.get(Calendar.DATE); int a, b, c, s, e, f, g, d, n; int week; if (month <= 2) { a = year - 1; b = a / 4 - a / 100 + a / 400; c = (a - 1) / 4 - (a - 1) / 100 + (a - 1) / 400; s = b - c; e = 0; f = day - 1 + 31 * (month - 1); } else { a = year; b = a / 4 - a / 100 + a / 400; c = (a - 1) / 4 - (a - 1) / 100 + (a - 1) / 400; s = b - c; e = s + 1; f = day + (153 * (month - 3) + 2) / 5 + 58 + s; } g = (a + b) % 7; d = (f + g - e) % 7; n = f + 3 - d; if (n < 0) { week = 53 - (g - s) / 5; year = year - 1; } else if (n > 364 + s) { week = 1; year = year + 1; } else { week = n / 7 + 1; } if (week < 10) { return "0" + week + " " + year; } else { return week + " " + year; } } }