Java Day of Week getIsoWeek(java.util.Date date)

Here you can find the source of getIsoWeek(java.util.Date date)

Description

Returns the week of the year according to the ISO 8601 specification.

License

Mozilla Public License

Parameter

Parameter Description
date the date object which week of year should be calculated

Return

the week of the year

Declaration

public static int getIsoWeek(java.util.Date date) 

Method Source Code

//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);
    }
}

Related

  1. getFirstWeekdayBetween(Date fromDate, Date toDate, int dayOfWeek)
  2. getFirstWeekofMonth(Date date1)
  3. getIntervalIncludeWeekend(Date date)
  4. getISO8601WeekOfYear(Date date)
  5. getIsoDayOfWeek(Date date)
  6. getLastDayFromLastWeek(Date d)
  7. getLastDayOfTheWeek(Date date)
  8. getLastDayOfWeek(Date date)
  9. getLastDayOfWeek(Date date)