Java Calendar Adjust adjustToFieldStart(Calendar cal, int[] fields)

Here you can find the source of adjustToFieldStart(Calendar cal, int[] fields)

Description

Set the calendar fields in the array to their actual (Considering the current Calendar time) minimum.

License

Open Source License

Parameter

Parameter Description
cal a parameter
fields a parameter

Declaration

public static void adjustToFieldStart(Calendar cal, int[] fields) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) Nov 2, 2012 NetXForge.//from  ww w. jav  a  2 s . c  om
 * 
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program 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 General Public License for more
 * details. You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>
 * 
 * Contributors: Christophe Bouhier - initial API and implementation and/or
 * initial documentation
 *******************************************************************************/

import java.util.Calendar;

public class Main {
    /**
     * Set the calendar fields in the array to their actual (Considering the
     * current Calendar time) minimum.
     * 
     * @param cal
     * @param fields
     */
    public static void adjustToFieldStart(Calendar cal, int[] fields) {

        for (int i = 0; i < fields.length; i++) {
            int f = fields[i];
            if (f == Calendar.DAY_OF_WEEK_IN_MONTH) {
                // int weekInMonth = cal.get(Calendar.WEEK_OF_MONTH);
                // Read the day of the week once. See bug:
                //
                cal.get(Calendar.DAY_OF_WEEK);
                cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
                // currentTime = cal.getTime();
            } else {
                cal.set(f, cal.getActualMinimum(f));
            }

        }
    }
}

Related

  1. adjustCalendar(Calendar calendar)
  2. adjustCalendarToLocalTime(Calendar cal)
  3. adjustDate(Calendar calendar, int differenceInDay)
  4. adjustedMillis(Calendar cal)
  5. adjustToDayEnd(Calendar cal)
  6. adjustToMonthStart(Calendar cal)
  7. getMidnightCalendarByUnadjustedDate(Date date, TimeZone timezone)
  8. truncCalendarToWeek(Calendar c, int adjustIncrement)
  9. truncCalendarToWeek(Calendar c, int adjustIncrement)