Here you can find the source of getIsoWeek(java.util.Date date)
Parameter | Description |
---|---|
date | the date object which week of year should be calculated |
public static int getIsoWeek(java.util.Date date)
//package com.java2s; /*/*from w w w . j av a 2s . c om*/ * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0, * and the EPL 1.0 (http://h2database.com/html/license.html). * Initial Developer: H2 Group * Iso8601: * Initial Developer: Robert Rathsack (firstName dot lastName at gmx dot de) */ import java.util.Calendar; public class Main { /** * Returns the week of the year according to the ISO 8601 specification. The * spec defines the first week of the year as the week which contains at * least 4 days of the new year. The week starts at Monday. Therefore * December 29th - 31th could belong to the next year and January 1st - 3th * could belong to the previous year. If January 1st is on Thursday (or * earlier) it belongs to the first week, otherwise to the last week of the * previous year. Hence January 4th always belongs to the first week while * the December 28th always belongs to the last week. * * @author Robert Rathsack * @param date the date object which week of year should be calculated * @return the week of the year */ public static int getIsoWeek(java.util.Date date) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(date.getTime()); c.setFirstDayOfWeek(Calendar.MONDAY); c.setMinimalDaysInFirstWeek(4); return c.get(Calendar.WEEK_OF_YEAR); } }