Author: sletellier Date: 2010-02-26 16:33:18 +0100 (Fri, 26 Feb 2010) New Revision: 1776 Modified: trunk/src/main/java/org/nuiton/util/DateUtils.java Log: Adding usefull method for date manipulations Modified: trunk/src/main/java/org/nuiton/util/DateUtils.java =================================================================== --- trunk/src/main/java/org/nuiton/util/DateUtils.java 2010-02-26 13:12:42 UTC (rev 1775) +++ trunk/src/main/java/org/nuiton/util/DateUtils.java 2010-02-26 15:33:18 UTC (rev 1776) @@ -273,6 +273,62 @@ } /** + * Get the date before today (so yesterday no ?) + * @param date concerned + * @return Date before today + */ + public static Date getLastDayDate(Date date) { + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + cal.roll(Calendar.DAY_OF_MONTH, false); + + return cal.getTime(); + } + + /** + * Get the first day of the current month + * @param date concerned + * @return Date of first day of current month + */ + public static Date getBeginMonthDate(Date date) { + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + cal.set(Calendar.DAY_OF_MONTH, 1); + + return cal.getTime(); + } + + /** + * Get the begin date of the day + * @param date concerned + * @return Date of the begin of the day + */ + public static Date getBeginOfDayDate(Date date) { + Calendar calBegin = Calendar.getInstance(); + calBegin.setTime(date); + calBegin.set(Calendar.HOUR, 0); + calBegin.set(Calendar.MINUTE, 0); + calBegin.set(Calendar.SECOND, 0); + + return calBegin.getTime(); + } + + /** + * Get the end date of the day + * @param date concerned + * @return Date of the end of the day + */ + public static Date getEndOfDayDate(Date date) { + Calendar calEnd = Calendar.getInstance(); + calEnd.setTime(date); + calEnd.set(Calendar.HOUR, 23); + calEnd.set(Calendar.MINUTE, 59); + calEnd.set(Calendar.SECOND, 59); + + return calEnd.getTime(); + } + + /** * Get the calendar corresponding to the {@code date}. The default calendar * will be returned (default time zone and locale). * @@ -284,5 +340,4 @@ calendar.setTime(date); return calendar; } - }
participants (1)
-
sletellier@users.nuiton.org