.periodUntil()
Published Nov 18, 2023
Contribute to Docs
The .periodUntil()
function is used to calculate the difference between two LocalDate
or Instant
instances. This returns an object representing the difference between the two dates in terms date or time components depending on if the arguments are LocalDate
or Instant
objects respectively.
Syntax
firstDate.periodUntil(secondDate)
firstDate
,secondDate
: Specific civil dates without a reference to a particular time zone.- The return is a
DatePeriod
object that yields the difference between the dates in either date or time units.
Note: This method is part of the
kotlinx-datetime
library and will require some configuration prior to use, please see their documentation for implementation details.
Example
In the example given below startDate
and endDate
are the LocalDate
instances representing the start-date and the end-date.
import kotlinx.datetime.*fun main() {val startDate = LocalDate(2023,11,2)val endDate = LocalDate(2023,11,3)val period = startDate.periodUntil(endDate)println("difference: $period")}
The result of the above code is as follows:
difference: P1D
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.
Learn Kotlin on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn Kotlin
Learn Kotlin, the expressive, open-source programming language developed by JetBrains.Beginner Friendly9 hours