Here you can find the source of getDay(long date, int startOfWeek, int increment)
private static long getDay(long date, int startOfWeek, int increment)
//package com.java2s; /*/*from w w w.j a va 2 s .c o m*/ * $Id: DateUtils.java,v 1.1 2004/08/12 00:24:33 dmouse Exp $ * * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ import java.util.*; public class Main { private static Calendar CALENDAR = Calendar.getInstance(); private static long getDay(long date, int startOfWeek, int increment) { Calendar calendar = CALENDAR; synchronized (calendar) { calendar.setTimeInMillis(date); int day = calendar.get(Calendar.DAY_OF_WEEK); // Normalize the view starting date to a week starting day while (day != startOfWeek) { calendar.add(Calendar.DATE, increment); day = calendar.get(Calendar.DAY_OF_WEEK); } return startOfDayInMillis(calendar.getTimeInMillis()); } } /** * Returns day in millis with the hours, milliseconds, seconds and minutes * set to 0. * * @param date long used in calculating start of day * @return Start of <code>date</code> */ public static long startOfDayInMillis(long date) { Calendar calendar = CALENDAR; synchronized (calendar) { calendar.setTimeInMillis(date); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MILLISECOND, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MINUTE, 0); return calendar.getTimeInMillis(); } } }