Java examples for java.util:Week
get date of Last Week
//package com.java2s; import java.util.Date; import java.util.GregorianCalendar; public class Main { public static Date[] getLastWeek() { GregorianCalendar calendar = new GregorianCalendar(); calendar.set(GregorianCalendar.HOUR_OF_DAY, 0); calendar.set(GregorianCalendar.MINUTE, 0); calendar.set(GregorianCalendar.SECOND, 0); int minus = calendar.get(GregorianCalendar.DAY_OF_WEEK); calendar.add(GregorianCalendar.DAY_OF_WEEK, -minus); calendar.set(GregorianCalendar.HOUR_OF_DAY, 23); calendar.set(GregorianCalendar.MINUTE, 59); calendar.set(GregorianCalendar.SECOND, 59); Date end = calendar.getTime(); calendar.add(GregorianCalendar.DAY_OF_WEEK, -6); calendar.set(GregorianCalendar.HOUR_OF_DAY, 0); calendar.set(GregorianCalendar.MINUTE, 0); calendar.set(GregorianCalendar.SECOND, 0); Date begin = calendar.getTime(); return new Date[] { begin, end }; }/*from w ww.jav a 2 s. c o m*/ }