Java Year Week getEndDayByWeekOfYear(int year, int weekNo)

Here you can find the source of getEndDayByWeekOfYear(int year, int weekNo)

Description

get the end day of given week no of a year.,the first day of week is Sunday

License

Open Source License

Parameter

Parameter Description
year a parameter
weekNo a parameter

Declaration

public static String getEndDayByWeekOfYear(int year, int weekNo) 

Method Source Code

//package com.java2s;

import java.util.Calendar;

public class Main {
    /**/*from w w  w . j  av a2s.  com*/
     * get the end day of given week no of a year.,the first day of week is Sunday
     * 
     * @param year
     * @param weekNo
     * @return
     */
    public static String getEndDayByWeekOfYear(int year, int weekNo) {
        Calendar cal = getCalendarFormYear(year);
        cal.set(Calendar.WEEK_OF_YEAR, weekNo);
        cal.add(Calendar.DAY_OF_WEEK, 6);
        int monthInt = cal.get(Calendar.MONTH) + 1;
        String monthString = monthInt < 10 ? "0" + monthInt : monthInt + "";
        int dayOfMontyInt = cal.get(Calendar.DAY_OF_MONTH);
        String dayOfMonth = dayOfMontyInt < 10 ? "0" + dayOfMontyInt : dayOfMontyInt + "";
        return cal.get(Calendar.YEAR) + "-" + monthString + "-" + dayOfMonth;
    }

    /**
     * get Calendar of given year
     * 
     * @param year
     * @return
     */
    private static Calendar getCalendarFormYear(int year) {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        cal.set(Calendar.YEAR, year);
        return cal;
    }
}

Related

  1. getLastDayOfWeek(int year, int week)
  2. getLastWeekOfYear()
  3. getMaxWeekNumOfYear(int year)
  4. getNextWeekMonday(int year, int weekOfYear)