Here you can find the source of alignWeek(Calendar timestamp)
Parameter | Description |
---|---|
timestamp | The calendar to align. |
public static Calendar alignWeek(Calendar timestamp)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { /**//from ww w. j a va 2 s. c om * Aligns the time fields to the start of the week. * @param timestamp The calendar to align. * @return The parameter. */ public static Calendar alignWeek(Calendar timestamp) { timestamp = alignDay(timestamp); int dayOfWeek = timestamp.get(Calendar.DAY_OF_WEEK); int offset = 1 - dayOfWeek; if (offset == 0) { return timestamp; } return addDays(offset, timestamp); } /** * Aligns the time fields to the start of the day. * @param timestamp The calendar to align. * @return The parameter. */ public static Calendar alignDay(Calendar timestamp) { timestamp.set(Calendar.HOUR_OF_DAY, 0); timestamp.set(Calendar.MINUTE, 0); timestamp.set(Calendar.SECOND, 0); timestamp.set(Calendar.MILLISECOND, 0); return timestamp; } /** * Adds or subtracts the corresponding time field, does not * perform any alignment. * @param count The quantity to change, can be negative. * @param timestamp The calendar to modify. * @return The timestamp parameter. */ public static Calendar addDays(int count, Calendar timestamp) { timestamp.add(Calendar.DATE, count); return timestamp; } }