Java Calendar Week getFirstDayOfWeek(Calendar cal)

Here you can find the source of getFirstDayOfWeek(Calendar cal)

Description

get First Day Of Week

License

Open Source License

Declaration

public static Calendar getFirstDayOfWeek(Calendar cal) 

Method Source Code

//package com.java2s;
/**/*from   w  w w. ja va 2s. c  o m*/
 * Copyright (c) Vietsoftware, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

import java.util.Calendar;

public class Main {
    public static Calendar getFirstDayOfWeek(Calendar cal) {

        switch (cal.get(Calendar.DAY_OF_WEEK)) {
        case 1:
            break;
        case 2:
            cal.add(Calendar.DATE, -1);
            break;
        case 3:
            cal.add(Calendar.DATE, -2);
            break;
        case 4:
            cal.add(Calendar.DATE, -3);
            break;
        case 5:
            cal.add(Calendar.DATE, -4);
            break;
        case 6:
            cal.add(Calendar.DATE, -5);
            break;
        case 7:
            cal.add(Calendar.DATE, -6);
            break;
        }

        return cal;
    }
}

Related

  1. getDayOfWeek(Calendar date)
  2. getDayOfWeekNumber(Calendar cal)
  3. getDayOfWeekString1(Calendar currentDate)
  4. getEndOfWeek(Calendar calendar, Date date, int dayStartOfWeek)
  5. getFirstDateInMonthForDayOfWeek(Calendar cal, final int dayOfWeek)
  6. getFirstDayOfWeek(Calendar calendar)
  7. getFirstOfMonthDayOfWeek(GregorianCalendar aCalendar)
  8. getImmediateDayOfWeek(Calendar current, int dayOfWeek)
  9. getLastDayOfWeek(Calendar cal)