Here you can find the source of getWeekStart(Date date)
Parameter | Description |
---|---|
date | the date |
public static Date getWeekStart(Date date)
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { /** The Constant MILLISECOND. */ public final static long MILLISECOND = 1l; /**/*from w w w .ja va2 s . c o m*/ * Returns week start date. * * @param date the date * @return week start date */ public static Date getWeekStart(Date date) { if (date == null) { return null; } Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); int day = calendar.get(Calendar.DAY_OF_WEEK); if (day == Calendar.SUNDAY) { calendar.add(Calendar.DAY_OF_WEEK, -6); return calendar.getTime(); } calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); return calendar.getTime(); } }