Class DateUtils

java.lang.Object
org.knowm.xchange.utils.DateUtils

public class DateUtils
extends Object
Utilities to provide the following to application:
  • Provision of standard date and time handling
  • Method Details

    • fromMillisUtc

      public static Date fromMillisUtc​(long millisecondsFromEpoch)
      Creates a date from a long representing milliseconds from epoch
      Parameters:
      millisecondsFromEpoch -
      Returns:
      the Date object
    • toUTCString

      public static String toUTCString​(Date date)
      Converts a date to a UTC String representation
      Parameters:
      date -
      Returns:
      the formatted date
    • toUTCISODateString

      public static String toUTCISODateString​(Date date)
    • toISODateString

      public static String toISODateString​(Date date)
    • fromISODateString

      public static Date fromISODateString​(String isoFormattedDate) throws com.fasterxml.jackson.databind.exc.InvalidFormatException
      Converts an ISO formatted Date String to a Java Date ISO format: yyyy-MM-dd'T'HH:mm:ss.SSS'Z'
      Parameters:
      isoFormattedDate -
      Returns:
      Date
      Throws:
      com.fasterxml.jackson.databind.exc.InvalidFormatException
    • fromISO8601DateString

      public static Date fromISO8601DateString​(String iso8601FormattedDate) throws com.fasterxml.jackson.databind.exc.InvalidFormatException
      Converts an ISO 8601 formatted Date String to a Java Date ISO 8601 format: yyyy-MM-dd'T'HH:mm:ss
      Parameters:
      iso8601FormattedDate -
      Returns:
      Date
      Throws:
      com.fasterxml.jackson.databind.exc.InvalidFormatException
    • fromRfc1123DateString

      public static Date fromRfc1123DateString​(String rfc1123FormattedDate, Locale locale) throws com.fasterxml.jackson.databind.exc.InvalidFormatException
      Converts an rfc1123 formatted Date String to a Java Date rfc1123 format: EEE, dd MMM yyyy HH:mm:ss zzz
      Parameters:
      rfc1123FormattedDate -
      Returns:
      Date
      Throws:
      com.fasterxml.jackson.databind.exc.InvalidFormatException
    • fromRfc3339DateString

      public static Date fromRfc3339DateString​(String rfc3339FormattedDate) throws com.fasterxml.jackson.databind.exc.InvalidFormatException
      Converts an RFC3339 formatted Date String to a Java Date RFC3339 format: yyyy-MM-dd HH:mm:ss
      Parameters:
      rfc3339FormattedDate - RFC3339 formatted Date
      Returns:
      an Date object
      Throws:
      com.fasterxml.jackson.databind.exc.InvalidFormatException - the RFC3339 formatted Date is invalid or cannot be parsed.
      See Also:
      The Internet Society - RFC 3339
    • toUnixTime

      public static long toUnixTime​(long javaTime)
      Convert java time long to unix time long, simply by dividing by 1000
    • toUnixTime

      public static long toUnixTime​(Date time)
      Convert java time to unix time long, simply by dividing by the time 1000
    • toUnixTimeNullSafe

      public static Long toUnixTimeNullSafe​(Date time)
      Convert java time to unix time long, simply by dividing by the time 1000. Null safe
    • toUnixTimeOptional

      public static Optional<Long> toUnixTimeOptional​(Date time)
    • toMillisNullSafe

      public static Long toMillisNullSafe​(Date time)
    • fromUnixTime

      public static Date fromUnixTime​(long unix)
      Convert unix time to Java Date