Class DateUtil


  • public class DateUtil
    extends java.lang.Object
    An utility class for Dates manipulations
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.util.regex.Pattern DIGIT_PATTERN
      Pattern to find digits only.
      private static java.util.TimeZone GMT_ZONE  
      private static java.util.Locale LOCALE  
      private static java.text.DateFormat RFC_1123_FORMAT  
      private static java.lang.String RFC_1123_PATTERN  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private DateUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String getCurrentAsString()  
      static java.lang.String getDateAsString​(java.util.Date date)
      Convert a given Date object to a RFC 1123 formatted String.
      private static long parseDateStringToMilliseconds​(java.lang.String dateString)
      Translate a given date String in the RFC 1123 format to a long representing the number of milliseconds since epoch.
      static long parseToMilliseconds​(java.lang.String dateValue)
      Parse a given date String to a long representation of the time.
      static java.lang.String parseToRFC1123​(long dateValue)
      Converts a millisecond representation of a date to a RFC 1123 formatted String.
      • Methods inherited from class java.lang.Object

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

      • LOCALE

        private static final java.util.Locale LOCALE
      • GMT_ZONE

        private static final java.util.TimeZone GMT_ZONE
      • RFC_1123_PATTERN

        private static final java.lang.String RFC_1123_PATTERN
        See Also:
        Constant Field Values
      • RFC_1123_FORMAT

        private static final java.text.DateFormat RFC_1123_FORMAT
      • DIGIT_PATTERN

        private static final java.util.regex.Pattern DIGIT_PATTERN
        Pattern to find digits only.
    • Constructor Detail

      • DateUtil

        private DateUtil()
    • Method Detail

      • getCurrentAsString

        public static java.lang.String getCurrentAsString()
        Returns:
        The current date as a string
      • parseDateStringToMilliseconds

        private static long parseDateStringToMilliseconds​(java.lang.String dateString)
        Translate a given date String in the RFC 1123 format to a long representing the number of milliseconds since epoch.
        Parameters:
        dateString - a date String in the RFC 1123 format.
        Returns:
        the parsed Date in milliseconds.
      • parseToMilliseconds

        public static long parseToMilliseconds​(java.lang.String dateValue)
        Parse a given date String to a long representation of the time. Where the provided value is all digits the value is returned as a long, otherwise attempt is made to parse the String as a RFC 1123 date.
        Parameters:
        dateValue - the value to parse.
        Returns:
        the long value following parse, or zero where not successful.
      • parseToRFC1123

        public static java.lang.String parseToRFC1123​(long dateValue)
        Converts a millisecond representation of a date to a RFC 1123 formatted String.
        Parameters:
        dateValue - the Date represented as milliseconds.
        Returns:
        a String representation of the date.
      • getDateAsString

        public static java.lang.String getDateAsString​(java.util.Date date)
        Convert a given Date object to a RFC 1123 formatted String.
        Parameters:
        date - the Date object to convert
        Returns:
        a String representation of the date.