Here you can find the source of getNumberOfWeeksInYear(int year)
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
Parameter | Description |
---|---|
year | the year of choice |
public static int getNumberOfWeeksInYear(int year)
//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); } }