Java Day of Week getWeekOfYear(Date date)

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

Description

The week of the year as an int from the given Date-object.

License

Apache License

Parameter

Parameter Description
date The Date-object to get the week of the year.

Return

The week of the year from the Date-object.

Declaration

public static int getWeekOfYear(Date date) 

Method Source Code

//package com.java2s;
/**/*from ww  w .j  ava 2s . c om*/
 * Copyright (C) 2007 Asterios Raptis
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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

public class Main {
    /**
     * The week of the year as an int from the given Date-object.
     *
     * @param date
     *            The Date-object to get the week of the year.
     * @return The week of the year from the Date-object.
     */
    public static int getWeekOfYear(Date date) {
        final Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(Calendar.WEEK_OF_YEAR);
    }
}

Related

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