Java Day of Week getFirstMonthWeek(Date month)

Here you can find the source of getFirstMonthWeek(Date month)

Description

Gets the first week which ends in specified month.

License

Open Source License

Parameter

Parameter Description
month initial month

Return

first day of first week of the month

Declaration

public static Date getFirstMonthWeek(Date month) 

Method Source Code


//package com.java2s;
import java.util.Calendar;
import java.util.Date;

public class Main {
    /** The Constant MILLISECOND. */
    public final static long MILLISECOND = 1l;

    /**//from  ww w .java 2  s .c  o  m
     * Gets the first week which ends in specified month.
     *
     * @param month initial month
     * @return first day of first week of the month
     */
    public static Date getFirstMonthWeek(Date month) {

        // Get last day of month
        Calendar firstWeek = Calendar.getInstance();
        firstWeek.setTime(month);
        firstWeek.set(Calendar.DATE, 1);
        firstWeek.set(Calendar.HOUR, 0);
        firstWeek.set(Calendar.MINUTE, 0);
        firstWeek.set(Calendar.SECOND, 0);
        firstWeek.set(Calendar.MILLISECOND, 0);
        firstWeek.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);

        return firstWeek.getTime();
    }
}

Related

  1. getFirstDayOfLastWeek(Date date)
  2. getFirstDayOfWeek(int year, int week)
  3. getFirstDayOfWeek(int year, int week)
  4. getFirstDayOfWeek(int year, int week)
  5. getFirstDayWeekly(final int year)
  6. getFirstWeekdayBetween(Date fromDate, Date toDate, int dayOfWeek)
  7. getFirstWeekofMonth(Date date1)
  8. getIntervalIncludeWeekend(Date date)
  9. getISO8601WeekOfYear(Date date)