Class DateTimeConverter

java.lang.Object
org.pipservices3.commons.convert.DateTimeConverter

public class DateTimeConverter extends Object
Converts arbitrary values into Date values. Converts using extended conversion rules:
  • Strings: converted using ISO time format
  • Numbers: converted using milliseconds since unix epoch

### Example ###

 
 ZonedDateTime value1 = DateTimeConverter.toNullableDateTime("ABC"); // Result: null
 ZonedDateTime value2 = DateTimeConverter.toNullableDateTime("2018-01-01T11:30:00.0"); // Result: ZonedDateTime(2018,0,1,11,30)
 ZonedDateTime value3 = DateTimeConverter.toNullableDateTime(123); // Result: ZonedDateTime(123)
 
 
  • Constructor Details

    • DateTimeConverter

      public DateTimeConverter()
  • Method Details

    • toNullableDateTime

      public static ZonedDateTime toNullableDateTime(Object value)
      Converts value into Date or returns null when conversion is not possible.
      Parameters:
      value - the value to convert.
      Returns:
      Date value or null when conversion is not supported.
    • toDateTime

      public static ZonedDateTime toDateTime(Object value)
      Converts value into Date or returns current date when conversion is not possible.
      Parameters:
      value - the value to convert.
      Returns:
      Date value or current date when conversion is not supported.
      See Also:
    • toDateTimeWithDefault

      public static ZonedDateTime toDateTimeWithDefault(Object value, ZonedDateTime defaultValue)
      Converts value into Date or returns default when conversion is not possible.
      Parameters:
      value - the value to convert.
      defaultValue - the default value.
      Returns:
      Date value or default when conversion is not supported.
      See Also: