Java Year Week getLastDayOfWeek(int year, int week)

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

Description

get Last Day Of Week

License

Open Source License

Declaration

public static Date getLastDayOfWeek(int year, int week) 

Method Source Code

//package com.java2s;

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

public class Main {
    public static Date getLastDayOfWeek(int year, int week) {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, Calendar.JANUARY);
        cal.set(Calendar.DATE, 1);

        Calendar c = (Calendar) cal.clone();
        c.add(Calendar.DATE, week * 7);
        return getEndTimeOfWeek(c.getTime());
    }/*from  w ww .  ja v a2 s . c o m*/

    private static Date add(Date date, int field, int amount) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(field, amount);
        return cal.getTime();
    }

    public static Date getEndTimeOfWeek(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setFirstDayOfWeek(Calendar.MONDAY);
        cal.setTime(date);
        cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY + 6);
        cal.set(Calendar.HOUR_OF_DAY, 23);
        cal.set(Calendar.MINUTE, 59);
        cal.set(Calendar.SECOND, 59);
        return cal.getTime();
    }
}

Related

  1. getEndDayByWeekOfYear(int year, int weekNo)
  2. getLastWeekOfYear()
  3. getMaxWeekNumOfYear(int year)
  4. getNextWeekMonday(int year, int weekOfYear)
  5. getNumberOfWeeksInYear(int year)