Class DateTimeUtil


  • public final class DateTimeUtil
    extends java.lang.Object
    This file is a helper class for internal usage only. Be aware that its API and functionality may be changed in future.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String DEFAULT_PATTERN  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private DateTimeUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Calendar addDaysToCalendar​(java.util.Calendar calendar, int days)
      Adds the specified amount of days to the given calendar field.
      static java.util.Date addDaysToDate​(java.util.Date date, int days)
      Adds the specified amount of days to the given date.
      static java.util.Date addMillisToDate​(java.util.Date date, long millis)
      Adds provided number of milliseconds to the Date.
      static java.util.Date addYearsToDate​(java.util.Date date, int years)
      Adds the specified amount of years to the given date.
      static java.lang.String dateToString​(java.util.Calendar date)
      Converts Calendar date to string of "yyyy.MM.dd HH:mm:ss z" format.
      static java.lang.String format​(java.util.Date date, java.lang.String pattern)
      Format passing date with specified pattern.
      static java.lang.String formatWithDefaultPattern​(java.util.Date date)
      Format passing date with default yyyy-MM-dd pattern.
      static java.util.Calendar getCalendar​(java.util.Date date)
      Gets the date as Calendar.
      static java.util.Calendar getCurrentTimeCalendar()
      Gets a default GregorianCalendar.
      static java.util.Date getCurrentTimeDate()
      Gets current time consistently.
      static long getCurrentTimeZoneOffset​(java.util.Date date)
      Gets the offset of time zone from UTC at the specified date.
      static long getRelativeTime​(java.util.Date date)
      Gets the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by specified date.
      static double getUtcMillisFromEpoch​(java.util.Calendar calendar)
      Gets the Calendar as UTC milliseconds from the epoch.
      private static java.text.DateFormat initParserSDF​(java.lang.String pattern)  
      static boolean isInPast​(java.util.Date date)
      Defines if date is in past.
      static java.util.Date parse​(java.lang.String date, java.lang.String format)
      Parses passing date with specified format.
      static java.util.Date parseWithDefaultPattern​(java.lang.String date)
      Parses passing date with default yyyy-MM-dd pattern.
      • Methods inherited from class java.lang.Object

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

    • Constructor Detail

      • DateTimeUtil

        private DateTimeUtil()
    • Method Detail

      • getUtcMillisFromEpoch

        public static double getUtcMillisFromEpoch​(java.util.Calendar calendar)
        Gets the Calendar as UTC milliseconds from the epoch.
        Parameters:
        calendar - the calendar to be converted to millis
        Returns:
        the date as UTC milliseconds from the epoch
      • getCalendar

        public static java.util.Calendar getCalendar​(java.util.Date date)
        Gets the date as Calendar.
        Parameters:
        date - the date to be returned as Calendar
        Returns:
        the date as Calendar
      • getCurrentTimeCalendar

        public static java.util.Calendar getCurrentTimeCalendar()
        Gets a default GregorianCalendar.
        Returns:
        a default GregorianCalendar using the current time in the default time zone with the default locale
      • getCurrentTimeDate

        public static java.util.Date getCurrentTimeDate()
        Gets current time consistently.
        Returns:
        the time at which it was allocated, measured to the nearest millisecond
      • addDaysToCalendar

        public static java.util.Calendar addDaysToCalendar​(java.util.Calendar calendar,
                                                           int days)
        Adds the specified amount of days to the given calendar field.
        Parameters:
        calendar - the calendar field where to add
        days - the amount of days to be added
        Returns:
        the time at which it was allocated, measured to the nearest millisecond
      • isInPast

        public static boolean isInPast​(java.util.Date date)
        Defines if date is in past.
        Parameters:
        date - the date to be compared with current date
        Returns:
        true if given date is in past, false instead
      • getRelativeTime

        public static long getRelativeTime​(java.util.Date date)
        Gets the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by specified date.
        Parameters:
        date - the specified date to get time
        Returns:
        the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by the specified date
      • addMillisToDate

        public static java.util.Date addMillisToDate​(java.util.Date date,
                                                     long millis)
        Adds provided number of milliseconds to the Date.
        Parameters:
        date - Date date to increase
        millis - number of milliseconds to add
        Returns:
        updated Date
      • addDaysToDate

        public static java.util.Date addDaysToDate​(java.util.Date date,
                                                   int days)
        Adds the specified amount of days to the given date.
        Parameters:
        date - the specified date to add
        days - the amount of days to be added
        Returns:
        a Date object representing the calendar's time value (millisecond offset from the Epoch)
      • addYearsToDate

        public static java.util.Date addYearsToDate​(java.util.Date date,
                                                    int years)
        Adds the specified amount of years to the given date.
        Parameters:
        date - the specified date to add
        years - the amount of years to be added
        Returns:
        a Date object representing the calendar's time value (millisecond offset from the Epoch)
      • parseWithDefaultPattern

        public static java.util.Date parseWithDefaultPattern​(java.lang.String date)
        Parses passing date with default yyyy-MM-dd pattern.
        Parameters:
        date - is date to be parse
        Returns:
        parse date
      • parse

        public static java.util.Date parse​(java.lang.String date,
                                           java.lang.String format)
        Parses passing date with specified format.
        Parameters:
        date - the date to be parsed
        format - the format of parsing the date
        Returns:
        parsed date
      • formatWithDefaultPattern

        public static java.lang.String formatWithDefaultPattern​(java.util.Date date)
        Format passing date with default yyyy-MM-dd pattern.
        Parameters:
        date - the date to be formatted
        Returns:
        formatted date
      • format

        public static java.lang.String format​(java.util.Date date,
                                              java.lang.String pattern)
        Format passing date with specified pattern.
        Parameters:
        date - date to be formatted
        pattern - pattern for format
        Returns:
        formatted date
      • getCurrentTimeZoneOffset

        public static long getCurrentTimeZoneOffset​(java.util.Date date)
        Gets the offset of time zone from UTC at the specified date.
        Parameters:
        date - the date represented in milliseconds since January 1, 1970 00:00:00 GMT
        Returns:
        the offset of time zone from UTC at the specified date adjusted with the amount of daylight saving.
      • dateToString

        public static java.lang.String dateToString​(java.util.Calendar date)
        Converts Calendar date to string of "yyyy.MM.dd HH:mm:ss z" format.
        Parameters:
        date - to convert.
        Returns:
        string date value.
      • initParserSDF

        private static java.text.DateFormat initParserSDF​(java.lang.String pattern)