.toInstant()
Published Nov 24, 2023
Contribute to Docs
The .toInstant()
method is a simple way to convert a date-time string into a Kotlin readable format. The conversion results in obtaining an Instant value, which is a standardized representation of time independent of time zones. Essentially, it helps transform a textual representation of a moment in time into a format that can be more easily manipulated and compared programmatically.
Syntax
fun String.toInstant(): Instant
Example
import kotlinx.datetime.toInstantfun main() {val iso8601String = "2023-11-13T11:04:44+00:00"val instant = iso8601String.toInstant()println(instant)}
The above code gives the following output:
2023-11-13T11:04:44Z
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.