Class DateTimeConverter


  • public final class DateTimeConverter
    extends java.lang.Object
    Utility class for datetime conversions
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.time.format.DateTimeFormatter getFormatter()
      Returns DateTimeFormatter used
      static <R> boolean isDateTime​(R value)
      Checks whether value provided belongs to datetime types or not
      static java.time.Instant toInstant​(java.time.LocalDate localDate)
      Converts local date to instant
      static java.time.Instant toInstant​(java.time.LocalDateTime localDateTime)
      Converts local datetime to instant
      static java.time.Instant toInstant​(java.util.Date date)
      Converts date to instant
      static <T> java.util.function.Function<T,​java.time.Instant> toInstantMapper()
      Returns function mapping datetime to instant
      static <R> java.lang.Long toLong​(R date)
      Converts datetime value to long (milliseconds)
      static java.lang.String toString​(java.time.Instant instant)
      Converts instant to string
      static java.lang.String toString​(java.time.LocalDate localDate)
      Converts local date to string
      static java.lang.String toString​(java.time.LocalDateTime dateTime)
      Converts local datetime to string
      static java.lang.String toString​(java.util.Date date)
      Converts date to string
      static <T> java.util.function.Function<T,​java.lang.String> toStringMapper()
      Returns function mapping datetime to string
      • Methods inherited from class java.lang.Object

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

      • toString

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

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

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

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

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

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

        public static java.time.Instant toInstant​(java.time.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> java.util.function.Function<T,​java.lang.String> toStringMapper()
        Returns function mapping datetime to string
        Type Parameters:
        T - Input parameter type
        Returns:
        Mapping function
      • toInstantMapper

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

        public static <R> java.lang.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 java.time.format.DateTimeFormatter getFormatter()
        Returns DateTimeFormatter used
        Returns:
        DateTimeFormatter instance