Java Day of Month getWeekOfFirstDayOfMonth(Date date)

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

Description

get Week Of First Day Of Month

License

Open Source License

Declaration

public static int getWeekOfFirstDayOfMonth(Date date) 

Method Source Code

//package com.java2s;

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

public class Main {
    public static int getWeekOfFirstDayOfMonth(Date date) {
        return getWeek(getFirstDayOfMonth(date));
    }//  ww  w  . ja v  a 2 s .  c  om

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

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

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

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

    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);
    }

    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();
    }
}

Related

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