/** * Dates Extracts the month of the given Date <b>starting at 1</b> (January=1, February=2, ...). * * @param date the date to extract the month from - must not be null. * @return the month of the given Date <b>starting at 1</b> (January=1, February=2, ...) * @throws NullPointerException if given Date is null */ public static int monthOf(Date date) { return toCalendar(date).get(Calendar.MONTH) + 1; // based 1 month (January=1) }
/** * Extracts the hour of day if the given Date (24-hour clock). * * @param date the date to extract the hour of day from - must not be null. * @return the hour of day of the given Date (24-hour clock) * @throws NullPointerException if given Date is null */ public static int hourOfDayOf(Date date) { return toCalendar(date).get(Calendar.HOUR_OF_DAY); }
/** * Extracts the day of week of the given Date, returned value follows {@link Calendar#DAY_OF_WEEK} . * * @param date the date to extract the day of week from - must not be null. * @return the day of week of the given Date * @throws NullPointerException if given Date is null */ public static int dayOfWeekOf(Date date) { return toCalendar(date).get(Calendar.DAY_OF_WEEK); }
/** * Dates Extracts the minute of the given Date. * * @param date the date to extract the minute from - must not be null. * @return the minute of the given Date * @throws NullPointerException if given Date is null */ public static int minuteOf(Date date) { return toCalendar(date).get(Calendar.MINUTE); }
/** * Dates Extracts the day of month of the given Date. * * @param date the date to extract the day of month from - must not be null. * @return the day of month of the given Date * @throws NullPointerException if given Date is null */ public static int dayOfMonthOf(Date date) { return toCalendar(date).get(Calendar.DAY_OF_MONTH); }
/** * Extracts the second of the given Date. * * @param date the date to extract the second from - must not be null. * @return the second of the given Date * @throws NullPointerException if given Date is null */ public static int secondOf(Date date) { return toCalendar(date).get(Calendar.SECOND); }
/** * Extracts the year of the given Date. * * @param date the date to extract the year from - must not be null. * @return the year of the given Date * @throws NullPointerException if given Date is null */ public static int yearOf(Date date) { return toCalendar(date).get(Calendar.YEAR); }
/** * Extracts the millisecond of the given Date. * * @param date the date to extract the millisecond from - must not be null. * @return the millisecond of the given Date * @throws NullPointerException if given Date is null */ public static int millisecondOf(Date date) { return toCalendar(date).get(Calendar.MILLISECOND); }
/** * Extracts the year of the given Date. * * @param date the date to extract the year from - must not be null. * @return the year of the given Date * @throws NullPointerException if given Date is null */ public static int yearOf(Date date) { return toCalendar(date).get(Calendar.YEAR); }
/** * Dates Extracts the day of month of the given Date. * * @param date the date to extract the day of month from - must not be null. * @return the day of month of the given Date * @throws NullPointerException if given Date is null */ public static int dayOfMonthOf(Date date) { return toCalendar(date).get(Calendar.DAY_OF_MONTH); }
/** * Extracts the millisecond of the given Date. * * @param date the date to extract the millisecond from - must not be null. * @return the millisecond of the given Date * @throws NullPointerException if given Date is null */ public static int millisecondOf(Date date) { return toCalendar(date).get(Calendar.MILLISECOND); }
/** * Dates Extracts the month of the given Date <b>starting at 1</b> (January=1, February=2, ...). * * @param date the date to extract the month from - must not be null. * @return the month of the given Date <b>starting at 1</b> (January=1, February=2, ...) * @throws NullPointerException if given Date is null */ public static int monthOf(Date date) { return toCalendar(date).get(Calendar.MONTH) + 1; // based 1 month (January=1) }
/** * Extracts the day of week of the given Date, returned value follows {@link Calendar#DAY_OF_WEEK} . * * @param date the date to extract the day of week from - must not be null. * @return the day of week of the given Date * @throws NullPointerException if given Date is null */ public static int dayOfWeekOf(Date date) { return toCalendar(date).get(Calendar.DAY_OF_WEEK); }
/** * Extracts the second of the given Date. * * @param date the date to extract the second from - must not be null. * @return the second of the given Date * @throws NullPointerException if given Date is null */ public static int secondOf(Date date) { return toCalendar(date).get(Calendar.SECOND); }
/** * Extracts the hour of day if the given Date (24-hour clock). * * @param date the date to extract the hour of day from - must not be null. * @return the hour of day of the given Date (24-hour clock) * @throws NullPointerException if given Date is null */ public static int hourOfDayOf(Date date) { return toCalendar(date).get(Calendar.HOUR_OF_DAY); }
/** * Dates Extracts the minute of the given Date. * * @param date the date to extract the minute from - must not be null. * @return the minute of the given Date * @throws NullPointerException if given Date is null */ public static int minuteOf(Date date) { return toCalendar(date).get(Calendar.MINUTE); }
/** * Returns a copy of the given date without the time part (which is set to 00:00:00), for example :<br> * <code>truncateTime(2008-12-29T23:45:12)</code> will give <code>2008-12-29T00:00:00</code>. * <p> * Returns null if the given Date is null. * * @param date we want to get the day part (the parameter is read only). * @return the truncated date. */ public static Date truncateTime(Date date) { if (date == null) return null; Calendar cal = toCalendar(date); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal.getTime(); }
/** * Returns a copy of the given date without the time part (which is set to 00:00:00), for example :<br> * <code>truncateTime(2008-12-29T23:45:12)</code> will give <code>2008-12-29T00:00:00</code>. * <p> * Returns null if the given Date is null. * * @param date we want to get the day part (the parameter is read only). * @return the truncated date. */ public static Date truncateTime(Date date) { if (date == null) return null; Calendar cal = toCalendar(date); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal.getTime(); }