Java Week of Year getWeekOfPreYearWeek(int year, int week)

Here you can find the source of getWeekOfPreYearWeek(int year, int week)

Description

get Week Of Pre Year Week

License

Apache License

Declaration

public static int getWeekOfPreYearWeek(int year, int week) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static int getWeekOfPreYearWeek(int year, int week) {
        return week == 1 ? getMaxWeekNumOfYear(year) : week - 1;
    }/*from w ww  .  j a  va 2 s.com*/

    public static int getMaxWeekNumOfYear(int year) {
        Calendar c = new GregorianCalendar();
        c.set(year, Calendar.DECEMBER, 31, 23, 59, 59);
        return getWeekNumber(c.getTime());
    }

    public static int getWeekNumber(Date date) {
        Calendar c = new GregorianCalendar();
        c.setFirstDayOfWeek(Calendar.MONDAY);
        c.setMinimalDaysInFirstWeek(7);
        c.setTime(date);

        return c.get(Calendar.WEEK_OF_YEAR);
    }
}

Related

  1. getWeekOfYear()
  2. getWeekOfYear(String year, String month, String day)
  3. getWeekOfYearByDay(String year, String month, String day)
  4. getWeekOfYearFromTimestamp(long ms)