Class DateUtils


  • public class DateUtils
    extends java.lang.Object
    Date related utility methods and constants
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.util.TimeZone MIDDAY
      Custom time zone used to interpret date values without a time component in a way that most likely falls within the same day regardless of in which time zone it is later interpreted.
      static java.util.TimeZone UTC
      The UTC time zone.
    • Constructor Summary

      Constructors 
      Constructor Description
      DateUtils()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String formatDate​(java.util.Calendar date)
      Returns a ISO 8601 representation of the given date.
      static java.lang.String formatDate​(java.util.Date date)
      Returns a ISO 8601 representation of the given date.
      static java.lang.String formatDateUnknownTimezone​(java.util.Date date)
      Returns a ISO 8601 representation of the given date, which is in an unknown timezone.
      java.util.Date tryToParse​(java.lang.String dateString)
      Tries to parse the date string; returns null if no parse was possible.
      • Methods inherited from class java.lang.Object

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

      • UTC

        public static final java.util.TimeZone UTC
        The UTC time zone. Not sure if TimeZone.getTimeZone(String) understands "UTC" in all environments, but it'll fall back to GMT in such cases, which is in practice equivalent to UTC.
      • MIDDAY

        public static final java.util.TimeZone MIDDAY
        Custom time zone used to interpret date values without a time component in a way that most likely falls within the same day regardless of in which time zone it is later interpreted. For example, the "2012-02-17" date would map to "2012-02-17T12:00:00Z" (instead of the default "2012-02-17T00:00:00Z"), which would still map to "2012-02-17" if interpreted in say Pacific time (while the default mapping would result in "2012-02-16" for UTC-8).
    • Constructor Detail

      • DateUtils

        public DateUtils()
    • Method Detail

      • formatDate

        public static java.lang.String formatDate​(java.util.Date date)
        Returns a ISO 8601 representation of the given date. This method is thread safe and non-blocking.
        Parameters:
        date - given date
        Returns:
        ISO 8601 date string, including timezone details
        See Also:
        TIKA-495
      • formatDate

        public static java.lang.String formatDate​(java.util.Calendar date)
        Returns a ISO 8601 representation of the given date. This method is thread safe and non-blocking.
        Parameters:
        date - given date
        Returns:
        ISO 8601 date string, including timezone details
        See Also:
        TIKA-495
      • formatDateUnknownTimezone

        public static java.lang.String formatDateUnknownTimezone​(java.util.Date date)
        Returns a ISO 8601 representation of the given date, which is in an unknown timezone. This method is thread safe and non-blocking.
        Parameters:
        date - given date
        Returns:
        ISO 8601 date string, without timezone details
        See Also:
        TIKA-495
      • tryToParse

        public java.util.Date tryToParse​(java.lang.String dateString)
        Tries to parse the date string; returns null if no parse was possible. This is not thread safe! Wrap in synchronized or create new DateUtils for each class.
        Parameters:
        dateString -
        Returns: