Class DateUtils


  • public class DateUtils
    extends Object
    Utility class for dates
    Author:
    Sebastien Briquet - sebfz1
    • Method Detail

      • utc

        public static long utc()
        Gets the current UTC date
        Returns:
        the current UTC date
      • utc

        public static long utc​(Date date)
        Converts a local date to a UTC date
        Parameters:
        date - the date to convert
        Returns:
        the UTC date
      • utc

        public static long utc​(long date)
        Converts a local date to a UTC date
        Parameters:
        date - the date to convert
        Returns:
        the UTC date
      • offset

        public static long offset​(long time)
        Gets the current timezone offset
        Parameters:
        time - the timestamp
        Returns:
        the timezone offset
        See Also:
        TimeZone.getRawOffset()
      • parse

        public static Date parse​(String date)
                          throws ParseException
        Converts a ISO8601 string date (without timezone) to a Date
        Parameters:
        date - ISO8601 string date
        Returns:
        the Date
        Throws:
        ParseException - if the string cannot be parsed
      • toString

        public static String toString​(Date date)
        Converts a date to its ISO8601/javascript representation (with timezone). ie: 2009-11-05T13:15:00.000+0200
        Parameters:
        date - the date to convert
        Returns:
        the ISO8601 date as string
      • toString

        public static String toString​(ZonedDateTime date)
        Converts a date to its ISO8601/javascript representation (with timezone). ie: 2009-11-05T13:15:00.000+0200
        Parameters:
        date - the date to convert
        Returns:
        the ISO8601 date as string
      • toUTCString

        public static String toUTCString​(Date date)
        Converts a date to its ISO8601/javascript representation (UTC). ie: 2009-11-05T13:15:00.000Z
        Parameters:
        date - the date to convert
        Returns:
        the ISO8601 date as string
      • toLocalDate

        public static LocalDate toLocalDate​(long timestamp)
        Converts a timestamp to a LocalDate
        Parameters:
        timestamp - the timestamp
        Returns:
        a new LocalDate
      • toLocalDate

        public static LocalDate toLocalDate​(Instant instant)
        Converts an Instant to a LocalDate
        Parameters:
        instant - the Instant
        Returns:
        a new LocalDate
      • toLocalTime

        public static LocalTime toLocalTime​(Date time)
        Converts an Date to a LocalTime
        Parameters:
        time - the Date
        Returns:
        a new LocalTime
      • toLocalTime

        public static LocalTime toLocalTime​(long timestamp)
        Converts a timestamp to a LocalTime
        Parameters:
        timestamp - the timestamp
        Returns:
        a new LocalTime
      • toLocalTime

        public static LocalTime toLocalTime​(Instant instant)
        Converts an Instant to a LocalTime
        Parameters:
        instant - the Instant
        Returns:
        a new LocalTime
      • toZuluDateTime

        public static ZonedDateTime toZuluDateTime​(long timestamp)
        Converts a timestamp to an UTC ZonedDateTime
        Parameters:
        timestamp - the timestamp
        Returns:
        a new ZonedDateTime
      • toZonedDateTime

        public static ZonedDateTime toZonedDateTime​(long timestamp,
                                                    ZoneOffset offset)
        Converts a timestamp to a ZonedDateTime
        Parameters:
        timestamp - the timestamp in milliseconds
        offset - the ZoneOffset
        Returns:
        a new ZonedDateTime