Class CalendarUtil


  • public class CalendarUtil
    extends java.lang.Object
    Useful utilities for creating views of a calendar.
    • Constructor Summary

      Constructors 
      Constructor Description
      CalendarUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addDaysToDate​(java.util.Date date, int days)
      Adds the given number of days to a date.
      static void addMonthsToDate​(java.util.Date date, int months)
      Adds the given number of months to a date.
      static java.util.Date copyDate​(java.util.Date date)
      Copies a date.
      static int getDaysBetween​(java.util.Date start, java.util.Date finish)
      Returns the number of days between the two dates.
      static int getStartingDayOfWeek()
      Returns the day of the week on which week starts in the current locale.
      static boolean isSameDate​(java.util.Date date0, java.util.Date date1)
      Check if two dates represent the same date of the same year, even if they have different times.
      (package private) static boolean isWeekend​(int dayOfWeek)
      Is a day in the week a weekend?
      static void resetTime​(java.util.Date date)
      Resets the date to have no time modifiers.
      static void setToFirstDayOfMonth​(java.util.Date date)
      Sets a date object to be at the beginning of the month and no time specified.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CalendarUtil

        public CalendarUtil()
    • Method Detail

      • addDaysToDate

        public static void addDaysToDate​(java.util.Date date,
                                         int days)
        Adds the given number of days to a date.
        Parameters:
        date - the date
        days - number of days
      • addMonthsToDate

        public static void addMonthsToDate​(java.util.Date date,
                                           int months)
        Adds the given number of months to a date.
        Parameters:
        date - the date
        months - number of months
      • copyDate

        public static java.util.Date copyDate​(java.util.Date date)
        Copies a date.
        Parameters:
        date - the date
        Returns:
        the copy
      • getDaysBetween

        public static int getDaysBetween​(java.util.Date start,
                                         java.util.Date finish)
        Returns the number of days between the two dates. Time is ignored.
        Parameters:
        start - starting date
        finish - ending date
        Returns:
        the different
      • getStartingDayOfWeek

        public static int getStartingDayOfWeek()
        Returns the day of the week on which week starts in the current locale. The range between 0 for Sunday and 6 for Saturday.
        Returns:
        the day of the week
      • isSameDate

        public static boolean isSameDate​(java.util.Date date0,
                                         java.util.Date date1)
        Check if two dates represent the same date of the same year, even if they have different times.
        Parameters:
        date0 - a date
        date1 - a second date
        Returns:
        true if the dates are the same
      • setToFirstDayOfMonth

        public static void setToFirstDayOfMonth​(java.util.Date date)
        Sets a date object to be at the beginning of the month and no time specified.
        Parameters:
        date - the date
      • isWeekend

        static boolean isWeekend​(int dayOfWeek)
        Is a day in the week a weekend?
        Parameters:
        dayOfWeek - day of week
        Returns:
        is the day of week a weekend?
      • resetTime

        public static void resetTime​(java.util.Date date)
        Resets the date to have no time modifiers. Note that the hour might not be zero if the time hits a DST transition date.
        Parameters:
        date - the date