Package org.pipservices3.commons.convert
Class DateTimeConverter
java.lang.Object
org.pipservices3.commons.convert.DateTimeConverter
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic ZonedDateTime
toDateTime
(Object value) Converts value into Date or returns current date when conversion is not possible.static ZonedDateTime
toDateTimeWithDefault
(Object value, ZonedDateTime defaultValue) Converts value into Date or returns default when conversion is not possible.static ZonedDateTime
toNullableDateTime
(Object value) Converts value into Date or returns null when conversion is not possible.
-
Constructor Details
-
DateTimeConverter
public DateTimeConverter()
-
-
Method Details
-
toNullableDateTime
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
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
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:
-