Class Dates


  • public class Dates
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String formatMillis​(java.time.format.DateTimeFormatter formatter, long epochMilli)
      Format epoch milliseconds to a string.
      static java.time.ZonedDateTime parse​(java.lang.String dateString)
      Return a ZonedDateTime that is set to the given datestring.
      static long parseMillis​(java.time.format.DateTimeFormatter formatter, java.lang.String time)
      Parse a string into epoch milliseconds.
      static java.time.ZonedDateTime toZonedDateTime​(long epochMilli)
      Return a new ZonedDateTime based on a epoch milliseconds.
      static java.time.ZonedDateTime toZonedDateTime​(java.time.LocalDate date, java.time.LocalTime time, java.time.ZoneId zone)
      Return a new ZonedDateTime based on a local date, time, and zone.
      static java.time.ZonedDateTime toZonedDateTime​(java.time.temporal.TemporalAccessor temporal)
      Turn a TemporalAccessor into a ZonedDateTime using defaults for missing fields.
      • Methods inherited from class java.lang.Object

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

      • UTC_ZONE_ID

        public static final java.time.ZoneId UTC_ZONE_ID
      • UTC_TIME_ZONE

        public static final java.util.TimeZone UTC_TIME_ZONE
      • RFC_7231_DATE_TIME

        public static final java.time.format.DateTimeFormatter RFC_7231_DATE_TIME
      • DATE_TOSTRING

        public static final java.time.format.DateTimeFormatter DATE_TOSTRING
    • Method Detail

      • parse

        public static java.time.ZonedDateTime parse​(java.lang.String dateString)
        Return a ZonedDateTime that is set to the given datestring. This will try all standard DateTimeFormatter formats and a bunch more. It does not support formats where the day and month are ambiguous. It is either year-month-day or day-month-year.
        Parameters:
        dateString - a date formatted string
        Returns:
        a ZonedDateTime or null if the string cannot be interpreted as a date
      • toZonedDateTime

        public static java.time.ZonedDateTime toZonedDateTime​(java.time.temporal.TemporalAccessor temporal)
        Turn a TemporalAccessor into a ZonedDateTime using defaults for missing fields. See toZonedDateTime(TemporalAccessor) for defaults.
        Parameters:
        temporal - the temporal to turn into ZonedDateTime
        Returns:
        a ZonedDateTime
      • toZonedDateTime

        public static java.time.ZonedDateTime toZonedDateTime​(java.time.LocalDate date,
                                                              java.time.LocalTime time,
                                                              java.time.ZoneId zone)
        Return a new ZonedDateTime based on a local date, time, and zone. Each can be null.
        Parameters:
        date - the localdate, when null, the current date is used
        time - the time, when null, 00:00:00.000 is used
        zone - the time zone, when null, UTC is used
        Returns:
        a ZonedDateTime
      • toZonedDateTime

        public static java.time.ZonedDateTime toZonedDateTime​(long epochMilli)
        Return a new ZonedDateTime based on a epoch milliseconds.
        Parameters:
        epochMilli - the number of milliseconds from 1970-01-01T00:00:00Z
        Returns:
        a ZonedDateTime using UTC time zone.
      • parseMillis

        public static long parseMillis​(java.time.format.DateTimeFormatter formatter,
                                       java.lang.String time)
        Parse a string into epoch milliseconds.
        Parameters:
        formatter - The formatter to parse the string with.
        time - Time string to parse into epoch milliseconds.
        Returns:
        The number of milliseconds from 1970-01-01T00:00:00Z.
      • formatMillis

        public static java.lang.String formatMillis​(java.time.format.DateTimeFormatter formatter,
                                                    long epochMilli)
        Format epoch milliseconds to a string.
        Parameters:
        formatter - The formatter to format the epoch milliseconds with.
        epochMilli - Number of milliseconds from 1970-01-01T00:00:00Z.
        Returns:
        Time string from the epoch milliseconds.