1 20 package org.enhydra.barracuda.plankton; 21 22 import java.util.Calendar ; 24 25 28 public class DateUtil { 29 30 34 38 42 46 public static Calendar getFirstDateToday() { 47 return DateUtil.getFirstDate(0); 48 } 49 50 public static Calendar getLastDateToday() { 51 return DateUtil.getLastDate(0); 52 } 53 54 public static Calendar getFirstDateTomorrow() { 55 return DateUtil.getFirstDate(1); 56 } 57 58 public static Calendar getLastDateTomorrow() { 59 return DateUtil.getLastDate(1); 60 } 61 62 public static Calendar getFirstDateYesterday() { 63 return DateUtil.getFirstDate(-1); 64 } 65 66 public static Calendar getLastDateYesterday() { 67 return DateUtil.getLastDate(-1); 68 } 69 70 public static Calendar getFirstDate(int theOffsetInDays) { 71 Calendar date = Calendar.getInstance(); 72 date.set(Calendar.MILLISECOND, 0); 73 date.set(Calendar.SECOND, 0); 74 date.set(Calendar.MINUTE, 0); 75 date.set(Calendar.HOUR_OF_DAY, 0); 76 date.add(Calendar.DATE, theOffsetInDays); 77 return date; 78 } 79 80 public static Calendar getLastDate(int theOffsetInDays) { 81 Calendar date = DateUtil.getFirstDate(theOffsetInDays + 1); 82 date.add(Calendar.MILLISECOND, -1); 83 return date; 84 } 85 86 90 94 public static final long SECONDS_IN_DAY = 24*60*60; 96 97 public static final long MILLISECONDS_IN_DAY = SECONDS_IN_DAY*1000; 99 100 } 101 | Popular Tags |