Published Nov 13, 2023Updated Nov 17, 2023
Contribute to Docs

The .daysUntil() method calculates the number of whole days between two instants and returns the result as an Int. If the number of days is too large to fit within the bounds of the Int datatype, the method will return Int.MAX_VALUE if the result is positive or Int.MIN_VALUE if the result is negative.


firstInstant.daysUntil(secondInstant, TimeZone)
  • firstInstant: The first reference time.
  • secondInstant: The second time.
  • TimeZone: The timezone that the calculation should consider zone when determining the number of days between the two Instant objects.


The example demonstrates the use of .daysUntil() to calculate the number of days between two Instants.

import kotlinx.datetime.*
fun main() {
val start = Instant.parse("2024-01-01T12:00:00Z")
val end = Instant.parse("2023-11-01T12:00:00Z")
val defaultTZ = TimeZone.currentSystemDefault()
val timeDelta = end.daysUntil(start, defaultTZ)

The output of this code will be:


All contributors

Looking to contribute?

Learn Kotlin on Codecademy