Java Day of Month getLastDayByMonthWeek(int year, int month, int week)

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

Description

get Last Day By Month Week

License

Open Source License

Declaration

public static String getLastDayByMonthWeek(int year, int month, int week) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.DateFormat;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    public final static String YYYY_MM_DD = "yyyy-MM-dd";

    public static String getLastDayByMonthWeek(int year, int month, int week) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd ");
        Calendar c = Calendar.getInstance();
        c.set(Calendar.YEAR, year);
        c.set(Calendar.MONTH, month - 1);
        c.set(Calendar.WEEK_OF_MONTH, week);

        int firstDayofweek = c.getFirstDayOfWeek();
        int lastDayofweek = firstDayofweek + 6;

        Calendar c2 = Calendar.getInstance();
        c2.set(Calendar.YEAR, year);
        c2.set(Calendar.MONTH, month - 1);
        c2.set(Calendar.WEEK_OF_MONTH, week);
        c2.set(Calendar.DAY_OF_WEEK, lastDayofweek);
        Date d2 = new Date(c2.getTimeInMillis());
        return df.format(d2);
    }//from   www . ja v a2  s  .  c om

    public static String format(Date date, String pattern) {
        if (date == null)
            return "";
        else
            return getFormatter(pattern).format(date);
    }

    public static String format(Date date) {
        if (date == null)
            return "";
        else
            return getFormatter(YYYY_MM_DD).format(date);
    }

    private static SimpleDateFormat getFormatter(String parttern) {
        return new SimpleDateFormat(parttern);
    }
}

Related

  1. getFirstMiddleDayOfMonth(Date date)
  2. getFistDayOfMonth(Date date)
  3. getFromDate(boolean invoiceSearchFromFirstDayOfMonth)
  4. getLastDateOfCurMonth()
  5. getLastDay(int year, int month)
  6. getLastDayInMonth(int year, int month)
  7. getLastDayOfCurMonth()
  8. getLastDayOfLastMonth()
  9. getLastDayOfMonth()