Here you can find the source of truncCalendarToWeek(Calendar c, int adjustIncrement)
Parameter | Description |
---|---|
adjustIncrement | +1 or -1 |
public static void truncCalendarToWeek(Calendar c, int adjustIncrement)
//package com.java2s; /******************************************************************************* * Copyright (c) 2010 BSI Business Systems Integration AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from w ww . j av a 2 s. c o m*/ * BSI Business Systems Integration AG - initial API and implementation ******************************************************************************/ import java.util.Calendar; public class Main { /** * truncate the calendar to week * * @param adjustIncrement * +1 or -1 */ public static void truncCalendarToWeek(Calendar c, int adjustIncrement) { if (adjustIncrement < -1) { adjustIncrement = -1; } if (adjustIncrement > 1) { adjustIncrement = 1; } if (adjustIncrement == 0) { adjustIncrement = -1; } c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); int firstDayOfWeek = Calendar.getInstance().getFirstDayOfWeek(); while (c.get(Calendar.DAY_OF_WEEK) != firstDayOfWeek) { c.add(Calendar.DATE, adjustIncrement); } } }