days

Returns a Duration equal to this Int number of days.

Note that a day in this conversion always represents exactly 24 hours. This is different from calendar days which may be longer or shorter than 24 hours when a daylight saving transition happens on that day.

Since Kotlin

1.6

Samples

import kotlin.test.*
import kotlin.time.*
import kotlin.time.Duration.Companion.days
import kotlin.time.Duration.Companion.hours
import kotlin.time.Duration.Companion.microseconds
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.nanoseconds
import kotlin.time.Duration.Companion.seconds

fun main() { 
   //sampleStart 
   println(366.days) // 366d
println(0.5.days) // 12h

// Large values can be converted to an infinite duration
println(100_000_000_000.days) // Infinity

// Double.NaN.days // will fail with IllegalArgumentException 
   //sampleEnd
}

Returns a Duration equal to this Long number of days.

Note that a day in this conversion always represents exactly 24 hours. This is different from calendar days which may be longer or shorter than 24 hours when a daylight saving transition happens on that day.

Since Kotlin

1.6

Samples

import kotlin.test.*
import kotlin.time.*
import kotlin.time.Duration.Companion.days
import kotlin.time.Duration.Companion.hours
import kotlin.time.Duration.Companion.microseconds
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.nanoseconds
import kotlin.time.Duration.Companion.seconds

fun main() { 
   //sampleStart 
   println(366.days) // 366d
println(0.5.days) // 12h

// Large values can be converted to an infinite duration
println(100_000_000_000.days) // Infinity

// Double.NaN.days // will fail with IllegalArgumentException 
   //sampleEnd
}

Returns a Duration equal to this Double number of days.

Depending on its magnitude, the value is rounded to an integer number of nanoseconds or milliseconds.

Note that a day in this conversion always represents exactly 24 hours. This is different from calendar days which may be longer or shorter than 24 hours when a daylight saving transition happens on that day.

Since Kotlin

1.6

Throws

if this Double value is NaN.

Samples

import kotlin.test.*
import kotlin.time.*
import kotlin.time.Duration.Companion.days
import kotlin.time.Duration.Companion.hours
import kotlin.time.Duration.Companion.microseconds
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.nanoseconds
import kotlin.time.Duration.Companion.seconds

fun main() { 
   //sampleStart 
   println(366.days) // 366d
println(0.5.days) // 12h

// Large values can be converted to an infinite duration
println(100_000_000_000.days) // Infinity

// Double.NaN.days // will fail with IllegalArgumentException 
   //sampleEnd
}