Here you can find the source of truncCalendarToWeek(Calendar c, int adjustIncrement)
public static void truncCalendarToWeek(Calendar c, int adjustIncrement)
//package com.java2s; /******************************************************************************* * Copyright (c) 2010-2015 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 w w. j a v a2s . co m * BSI Business Systems Integration AG - initial API and implementation ******************************************************************************/ import java.util.Calendar; public class Main { public static void truncCalendarToWeek(Calendar c, int adjustIncrement) { truncCalendarToWeek(c, adjustIncrement, Calendar.getInstance().getFirstDayOfWeek()); } /** * truncate the calendar to week * * @param adjustIncrement * +1 or -1 */ public static void truncCalendarToWeek(Calendar c, int adjustIncrement, int firstDayOfWeek) { if (c == null) { return; } 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); while (c.get(Calendar.DAY_OF_WEEK) != firstDayOfWeek) { c.add(Calendar.DATE, adjustIncrement); } } }