Java Year Week getNumberOfWeeksInYear(int year)

Here you can find the source of getNumberOfWeeksInYear(int year)

Description

Computes the number of weeks in a given year See: http://stackoverflow.com/questions/18438332/how-to-get-total-number-of-week-in-the-current-year

License

Apache License

Parameter

Parameter Description
year the year of choice

Return

the number of weeks in the year

Declaration

public static int getNumberOfWeeksInYear(int year) 

Method Source Code

//package com.java2s;
/*//from  www. jav  a 2s .com
 * Copyright 2016 Danish Maritime Authority.
 *
 * 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.GregorianCalendar;

public class Main {
    /**
     * Computes the number of weeks in a given year
     * See: http://stackoverflow.com/questions/18438332/how-to-get-total-number-of-week-in-the-current-year
     *
     * @param year the year of choice
     * @return the number of weeks in the year
     */
    public static int getNumberOfWeeksInYear(int year) {
        GregorianCalendar cal = new GregorianCalendar(year, 12, 31);
        cal.setFirstDayOfWeek(Calendar.MONDAY); // week begin from Monday
        cal.setMinimalDaysInFirstWeek(4); // 1 week minimum from Thursday
        return cal.getMaximum(Calendar.WEEK_OF_YEAR);
    }
}

Related

  1. getEndDayByWeekOfYear(int year, int weekNo)
  2. getLastDayOfWeek(int year, int week)
  3. getLastWeekOfYear()
  4. getMaxWeekNumOfYear(int year)
  5. getNextWeekMonday(int year, int weekOfYear)
  6. getSeasonStartWeekOffset(int year)
  7. getStartDayOfWeekNo(int year, int weekNo)
  8. getTotalWeekOfYear(int year)
  9. getYmd(int year, int week, int days)