Java Day of Week getWeekNumber(Date date)

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

Description

get Week Number

License

Open Source License

Declaration

public static long getWeekNumber(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 long getWeekNumber(Date date) {
        long retVal = 0;

        if (date != null) {

            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);/*from  www.  j ava  2s .  com*/

            if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
                calendar.add(Calendar.DAY_OF_YEAR, -1);
            }

            calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);

            return calendar.get(Calendar.WEEK_OF_YEAR);

        }

        return retVal;

    }
}

Related

  1. getWeekDaysBetween(Date fromDate, Date toDate, int dayOfWeek)
  2. getWeekEnd(Date date, int w)
  3. getWeekFirstDay(Date weekday)
  4. getWeekID(Date dateValue)
  5. getWeekNum(Date date)
  6. getWeekNumber(Date date, Integer day)
  7. getWeekNumberFromDate(Date date)
  8. getWeekNumOfYear(Date date)
  9. getWeekOfDate(Date dt)