Class DateUtil


  • public final class DateUtil
    extends Object
    A utility class that centralizes processing of dates.
    • Field Detail

      • MILLISECONDS_IN_DAY

        public static final int MILLISECONDS_IN_DAY
        The milliseconds in a day.
        See Also:
        Constant Field Values
    • Method Detail

      • formatDateTime

        public static String formatDateTime​(Date date)
        Formats a date according ISO 8601 full date time format. Currently, this is used to print dates for error messages.
        Parameters:
        date - the date to format as a string
        Returns:
        a string representing the date in ISO 8601 format
      • serializeDate

        public static String serializeDate​(Date date)
        Converts date into a string containing the milliseconds since the UNIX Epoch.
        Parameters:
        date - the date to serialize as a string
        Returns:
        a string representing the date as milliseconds since the UNIX Epoch
      • deserializeDate

        public static Date deserializeDate​(String date)
        Converts a string containing the milliseconds since the UNIX Epoch into a Date. Two formats of date string are supported: "yyyy-MM-dd" and a long. Eventually, the "yyyy-MM-dd" format support will be removed.
        Parameters:
        date - the date string to deserialize into a date
        Returns:
        a date
      • getEpochPlusDays

        public static final Date getEpochPlusDays​(int days,
                                                  int milliseconds)
        Constructs a Date set to the UNIX Epoch plus days plus milliseconds.
        Parameters:
        days - the number of days to add to the UNIX Epoch to get a Date
        milliseconds - the number of milliseconds to add to the date
        Returns:
        the Date with number of days plus Epoch