Here you can find the source of adjustToFieldStart(Calendar cal, int[] fields)
Parameter | Description |
---|---|
cal | a parameter |
fields | a parameter |
public static void adjustToFieldStart(Calendar cal, int[] fields)
//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)); } } } }