Kotlin Convert String to DateTime

In the tutorial, JavaSampleApproach will show how to convert Kotlin String to DateTime by using java.time.* package of Java 8.

1. Kotlin convert String to LocalDate

We use method parse() of LocalDate class to convert String to LocalDate.
Methods signatures:

Practice:

2. Kotlin convert String to LocalTime

We use method parse() of LocalTime class to convert String to LocalTime.
Methods signatures:

Practice:

3. Kotlin convert String to LocalDateTime

We use method parse() of LocalDateTime class to convert String to LocalDateTime.
Methods signatures:

Practice:

4. Kotlin convert String to ZonedDateTime

We use method parse() of ZonedDateTime class to convert String to ZonedDateTime.
Methods signatures:

Practice:

We also use java.time.Instant class with parse() to convert String to ZonedDateTime.
Method signature:

-> The string must represent a valid instant in UTC and is parsed using DateTimeFormatter.ISO_INSTANT such as 2018-01-28T08:00:59.394Z.

By JavaSampleApproach | January 28, 2018.


Related Posts


Got Something To Say:

Your email address will not be published. Required fields are marked *

*