Java Week Calculate weekStart()

Here you can find the source of weekStart()

Description

week Start

License

LGPL

Return

the starting moment of the current week

Declaration

public static GregorianCalendar weekStart() 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.util.*;

public class Main {
    /** First day of work within a week */
    public static final int FIRST_DAY_OF_WORK = Calendar.MONDAY;

    /**/*w w  w.j  a v  a 2s . c  o m*/
       @return the starting moment of the current week
     */
    public static GregorianCalendar weekStart() {
        return weekStart(new GregorianCalendar());
    }

    /**
       @return the starting moment of the week containing the given date
       Note that it is set to the FIRST_DAY_OF_WORK.
     */
    public static GregorianCalendar weekStart(GregorianCalendar cal) {
        GregorianCalendar newCal = (GregorianCalendar) cal.clone();
        newCal.set(Calendar.DAY_OF_WEEK, FIRST_DAY_OF_WORK);
        newCal.set(Calendar.HOUR_OF_DAY, 0);
        newCal.set(Calendar.MINUTE, 0);
        newCal.set(Calendar.SECOND, 0);
        newCal.set(Calendar.MILLISECOND, 0);
        return newCal;
    }
}

Related

  1. startOfWeek(Date datum)
  2. weekCal(int weekNumber)
  3. weekCount(Date start, Date end)
  4. weekNumber()
  5. weeksInYear(int year)