toInstant

fun Long.toInstant(): Instant

Convert Long to Instant.

Example:

1659814200000.toInstant() // 2022-08-06T19:30:00Z

Since

1.1.0


fun String.toInstant(pattern: String = "EEE MMM dd HH:mm:ss zzz yyyy"): Instant

Produce an Instant from the given strings value and pattern.

Example:

"8/7/2022".toInstant("MM/dd/yyyy") // 2022-08-06T19:30:00Z
"Sun Aug 07 16:37:42 IRDT 2022".toInstant() // 2022-08-07T12:07:42Z
"7/2022".toInstant("MM/dd/yyyy") // ParseException

Since

1.1.0

Return

An Instant parsed from the string.

See also

Throws

if the beginning of the specified string cannot be parsed.

IllegalArgumentException

if the given pattern is invalid