Class ISO8601Util


  • public final class ISO8601Util
    extends Object
    The ISO8601Util class provides a helper class for handling ISO 8601 strings of the following format: "2008-03-01T13:00:00+01:00". It also supports parsing the "Z" timezone.
    Author:
    Marcus Portmann
    • Constructor Detail

      • ISO8601Util

        public ISO8601Util()
    • Method Detail

      • fromDate

        public static String fromDate​(Date date)
        Transform the Date instance into an ISO 8601 string.
        Parameters:
        date - the Date instance to transform into an ISO 8601 string
        Returns:
        the ISO 8601 string for the Date instance
      • fromDateTime

        public static String fromDateTime​(Date date)
        Transform the Date instance into an ISO 8601 string.
        Parameters:
        date - the Date instance to transform into an ISO 8601 string
        Returns:
        the ISO 8601 string for the Date instance
      • fromLocalDate

        public static String fromLocalDate​(LocalDate localDate)
        Transform the LocalDate instance into an ISO 8601 string.
        Parameters:
        localDate - the LocalDate instance to transform into an ISO 8601 string
        Returns:
        the ISO 8601 string for the LocalDate instance
      • fromLocalDateTimeAsUTC

        public static String fromLocalDateTimeAsUTC​(LocalDateTime localDateTime)
        Transform the LocalDateTime instance into an ISO 8601 string.
        Parameters:
        localDateTime - the LocalDateTime instance to transform into an ISO 8601 string
        Returns:
        the ISO 8601 string for the LocalDateTime instance
      • fromLocalDateTime

        public static String fromLocalDateTime​(LocalDateTime localDateTime)
        Transform the LocalDateTime instance into an ISO 8601 string.
        Parameters:
        localDateTime - the LocalDateTime instance to transform into an ISO 8601 string
        Returns:
        the ISO 8601 string for the LocalDateTime instance
      • fromLocalTime

        public static String fromLocalTime​(LocalTime localTime)
        Transform the LocalTime instance into an ISO 8601 string.
        Parameters:
        localTime - the LocalTime instance to transform into an ISO 8601 string
        Returns:
        the ISO 8601 string for the LocalTime instance
      • fromZonedDateTime

        public static String fromZonedDateTime​(ZonedDateTime zonedDateTime)
        Transform the ZonedDateTime instance into an ISO 8601 string.
        Parameters:
        zonedDateTime - the ZonedDateTime instance to transform into an ISO 8601 string
        Returns:
        the ISO 8601 string for the ZonedDateTime instance
      • now

        public static String now()
        Get current date and time formatted as ISO 8601 string.
        Returns:
        the current date and time formatted as ISO 8601 string
      • toDate

        public static Date toDate​(String iso8601string)
        Transform ISO 8601 string into a LocalDate instance.
        Parameters:
        iso8601string - the ISO 8601 string to transform
        Returns:
        the LocalDate instance for the ISO 8601 string
      • toLocalDate

        public static LocalDate toLocalDate​(String iso8601string)
        Transform ISO 8601 string into a LocalDate instance.
        Parameters:
        iso8601string - the ISO 8601 string to transform
        Returns:
        the LocalDate instance for the ISO 8601 string
      • toLocalDateTime

        public static LocalDateTime toLocalDateTime​(String iso8601string)
        Transform ISO 8601 string into a LocalDateTime instance.
        Parameters:
        iso8601string - the ISO 8601 string to transform
        Returns:
        the LocalDateTime instance for the ISO 8601 string
      • toLocalTime

        public static LocalTime toLocalTime​(String iso8601string)
        Transform ISO 8601 string into a LocalTime instance.
        Parameters:
        iso8601string - the ISO 8601 string to transform
        Returns:
        the LocalTime instance for the ISO 8601 string
      • toZonedDateTime

        public static ZonedDateTime toZonedDateTime​(String iso8601string)
        Transform ISO 8601 string into a ZonedDateTime instance.
        Parameters:
        iso8601string - the ISO 8601 string to transform
        Returns:
        the ZonedDateTime instance for the ISO 8601 string