Java Day of Week getWeekOfYear(Date date)

Here you can find the source of getWeekOfYear(Date date)

Description

get Week Of Year

License

Open Source License

Declaration

public static int getWeekOfYear(Date date) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Calendar;
import java.util.Date;

public class Main {
    public static int getWeekOfYear(Date date) {
        Calendar calendar = getCalendarFromDate(date);
        calendar.setFirstDayOfWeek(Calendar.MONDAY);
        return calendar.get(Calendar.WEEK_OF_YEAR) - 1;
    }/*from  w w  w. ja  v  a 2s  .c o m*/

    /**
     * get calendar from date
     *
     * @param date the passing date
     * @return the calendar instance
     */
    public static Calendar getCalendarFromDate(Date date) {
        Calendar calendar = getDefaultCalendar();
        calendar.setTime(date);
        return calendar;
    }

    /**
     * get the default calendar
     *
     * @return the calendar instance
     */
    public static Calendar getDefaultCalendar() {
        Calendar calendar = Calendar.getInstance();
        calendar.setFirstDayOfWeek(Calendar.MONDAY);
        return calendar;
    }
}

Related

  1. getWeekOfMonthFirstDay(Date dt)
  2. getWeekOfTheYear(Date aDate)
  3. getWeekOfTheYear(final Date dateOfYear)
  4. getWeekOfYear(Date d, Locale locale)
  5. getWeekOfYear(Date date)
  6. getWeekOfYear(Date date)
  7. getWeekOfYear(String date)
  8. getWeeksBetweenDate(Date begin, Date end)
  9. getWeekStart(Date date)