Software Development

Kotlin – Using Java 8 Date and Time API

Kotlin key exists Map

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


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


Using java.time.LocalDateTime


Using java.time.LocalTime


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.


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.


Using java.time.temporal.ChronoUnit


Download the codes


Got comments, or suggestions? Please visit our Facebook page!

You Might Also Like

One comment

  1. 1

    I simply wanted to thank you so much again. I am not sure the things
    that I might have gone through without the type of hints revealed by
    you regarding that situation.

Comments are closed.