Java Day of Month getWeekOfLastDayOfMonth(Date date)

Here you can find the source of getWeekOfLastDayOfMonth(Date date)

Description

get Week Of Last Day Of Month

License

Open Source License

Declaration

public static int getWeekOfLastDayOfMonth(Date date) 

Method Source Code

//package com.java2s;

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

public class Main {
    public static int getWeekOfLastDayOfMonth(Date date) {
        return getWeek(getLastDayOfMonth(date));
    }/*from  w w  w. j a  va2s  . c  om*/

    public static int getWeek(Date date) {
        return getCalendar(date).get(7);
    }

    public static Date getLastDayOfMonth() {
        return getLastDayOfMonth(null);
    }

    public static Date getLastDayOfMonth(Date date) {
        Calendar c = getCalendar(getFirstDayOfMonth(date));
        c.add(2, 1);
        c.add(5, -1);
        return getCleanDay(c);
    }

    public static Calendar getCalendar(Date day) {
        Calendar c = Calendar.getInstance();
        if (day != null)
            c.setTime(day);
        return c;
    }

    public static Date getFirstDayOfMonth(Date date) {
        return getFirstCleanDay(5, date);
    }

    public static Date getFirstDayOfMonth() {
        return getFirstDayOfMonth(null);
    }

    private static Date add(int datePart, int detal, Date date) {
        Calendar c = Calendar.getInstance();
        if (date != null)
            c.setTime(date);
        c.add(datePart, detal);
        return c.getTime();
    }

    public static Date getCleanDay(Date day) {
        return getCleanDay(getCalendar(day));
    }

    private static Date getCleanDay(Calendar c) {
        c.set(11, 0);
        c.clear(12);
        c.clear(13);
        c.clear(14);
        return c.getTime();
    }

    private static Date getFirstCleanDay(int datePart, Date date) {
        Calendar c = Calendar.getInstance();
        if (date != null)
            c.setTime(date);
        c.set(datePart, 1);
        return getCleanDay(c);
    }
}

Related

  1. getLastDayOfMonth(String year, String month)
  2. getLastDayOfTheMonth(String dateOfString)
  3. getLastDayOfXMonth(Date date, String xMonth)
  4. getToDate(boolean invoiceSearchFromFirstDayOfMonth)
  5. getWeekOfFirstDayOfMonth(Date date)
  6. isGivenDayOfMonth(java.util.Date date, int dayOfMonth)
  7. isSameDayOfMonth(Date dt1, Date dt2)
  8. newDate(int year, int month, int dayOfMonth)
  9. setDayOfMonth(Date d, int date)