Software Development

Kotlin – Using Java 8 Date and Time API

This post shows sample Kotlin codes that use the Java 8 Date and Time API (java.time).

Requirements

These are Software applications used for this post.

  • IntelliJ IDEA Ultimate 2016.3
    • The Community Edition may be enough but we have not tried it.
  • Kotlin Version 1.1
  • Windows 10 Enterprise

Using java.time.LocalDate

Outputs:

Using java.time.LocalDateTime

Outputs:

Using java.time.LocalTime

Outputs:

Using java.time.Duration

Note that java.time.Duration works with classes that store both date and time. Depending on how we use Duration, it works with classes too that only store time.

Outputs:

Using java.time.Period

Note that java.time.Period works with both classes that store date/time and date only. However. it will not work with classes that store time only.

Outputs:

Using java.time.temporal.ChronoUnit

Outputs:

Download the codes

https://github.com/Turreta/Kotlin-Using-Java-8-Date-and-Time-API

References

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like