| 10 | import java.util.List; |
| 11 | |
| 12 | public class DateUtils { |
| 13 | |
| 14 | // 获取当天的开始时间 |
| 15 | public static Date getDayBegin() { |
| 16 | Calendar cal = new GregorianCalendar(); |
| 17 | cal.set(Calendar.HOUR_OF_DAY, 0); |
| 18 | cal.set(Calendar.MINUTE, 0); |
| 19 | cal.set(Calendar.SECOND, 0); |
| 20 | cal.set(Calendar.MILLISECOND, 0); |
| 21 | return cal.getTime(); |
| 22 | } |
| 23 | |
| 24 | // 获取当天的结束时间 |
| 25 | public static Date getDayEnd() { |
| 26 | Calendar cal = new GregorianCalendar(); |
| 27 | cal.set(Calendar.HOUR_OF_DAY, 23); |
| 28 | cal.set(Calendar.MINUTE, 59); |
| 29 | cal.set(Calendar.SECOND, 59); |
| 30 | return cal.getTime(); |
| 31 | } |
| 32 | |
| 33 | // 获取昨天的开始时间 |
| 34 | public static Date getBeginDayOfYesterday() { |
| 35 | Calendar cal = new GregorianCalendar(); |
| 36 | cal.setTime(getDayBegin()); |
| 37 | cal.add(Calendar.DAY_OF_MONTH, -1); |
| 38 | return cal.getTime(); |
| 39 | } |
| 40 | |
| 41 | // 获取昨天的结束时间 |
| 42 | public static Date getEndDayOfYesterDay() { |
| 43 | Calendar cal = new GregorianCalendar(); |
| 44 | cal.setTime(getDayEnd()); |
| 45 | cal.add(Calendar.DAY_OF_MONTH, -1); |
| 46 | return cal.getTime(); |
| 47 | } |
| 48 | |
| 49 | // 获取明天的开始时间 |
| 50 | public static Date getBeginDayOfTomorrow() { |
| 51 | Calendar cal = new GregorianCalendar(); |
| 52 | cal.setTime(getDayBegin()); |
| 53 | cal.add(Calendar.DAY_OF_MONTH, 1); |
| 54 | return cal.getTime(); |
| 55 | } |
| 56 | |
| 57 | // 获取明天的结束时间 |
| 58 | public static Date getEndDayOfTomorrow() { |
| 59 | Calendar cal = new GregorianCalendar(); |
| 60 | cal.setTime(getDayEnd()); |
| 61 | cal.add(Calendar.DAY_OF_MONTH, 1); |
| 62 | return cal.getTime(); |
| 63 | } |
| 64 | |
| 65 | // 获取本周的开始时间 |
| 66 | @SuppressWarnings("unused") |
| 67 | public static Date getBeginDayOfWeek() { |
| 68 | Date date = new Date(); |
| 69 | if (date == null) { |
nothing calls this directly
no outgoing calls
no test coverage detected