Class DateTimeConverter


  • public final class DateTimeConverter
    extends Object
    Utility class for datetime conversions
    • Method Detail

      • toString

        public static String toString​(Date date)
        Converts date to string
        Parameters:
        date - Date instance
        Returns:
        String representation of date
      • toString

        public static String toString​(Instant instant)
        Converts instant to string
        Parameters:
        instant - Instant instance
        Returns:
        String representation of instant
      • toString

        public static String toString​(LocalDate localDate)
        Converts local date to string
        Parameters:
        localDate - LocalDate instance
        Returns:
        String representation of localDate
      • toString

        public static String toString​(LocalDateTime dateTime)
        Converts local datetime to string
        Parameters:
        dateTime - LocalDateTime instance
        Returns:
        String representation of local dateTime
      • toInstant

        public static Instant toInstant​(Date date)
        Converts date to instant
        Parameters:
        date - Date instance
        Returns:
        Instant instance
      • toInstant

        public static Instant toInstant​(LocalDate localDate)
        Converts local date to instant
        Parameters:
        localDate - LocalDate instance
        Returns:
        Instant instance
      • toInstant

        public static Instant toInstant​(LocalDateTime localDateTime)
        Converts local datetime to instant
        Parameters:
        localDateTime - LocalDateTime instance
        Returns:
        Instant instance
      • isDateTime

        public static <R> boolean isDateTime​(R value)
        Checks whether value provided belongs to datetime types or not
        Type Parameters:
        R - Return parameter type
        Parameters:
        value - Value to check
        Returns:
        True or false
      • toStringMapper

        public static <T> Function<T,​String> toStringMapper()
        Returns function mapping datetime to string
        Type Parameters:
        T - Input parameter type
        Returns:
        Mapping function
      • toInstantMapper

        public static <T> Function<T,​Instant> toInstantMapper()
        Returns function mapping datetime to instant
        Type Parameters:
        T - Input parameter type
        Returns:
        Mapping function
      • toLong

        public static <R> Long toLong​(R date)
        Converts datetime value to long (milliseconds)
        Type Parameters:
        R - Return parameter type
        Parameters:
        date - Datetime value to be converted
        Returns:
        Long
      • getFormatter

        public static DateTimeFormatter getFormatter()
        Returns DateTimeFormatter used
        Returns:
        DateTimeFormatter instance