fromMillisecondOfDay

actual fun fromMillisecondOfDay(millisecondOfDay: Int): LocalTime(source)
expect fun fromMillisecondOfDay(millisecondOfDay: Int): LocalTime(source)

Constructs a LocalTime that represents the specified number of milliseconds since the start of a calendar day. The sub-millisecond parts of the LocalTime will be zero.

See also

Throws

if millisecondOfDay is outside the 0 until 86400 * 1_000 range, with 86400 being the number of seconds in a calendar day.

It is incorrect to pass to this function the number of milliseconds that have physically elapsed since the start of the day. The reason is that, due to the daylight-saving-time transitions, the number of milliseconds since the start of the day is not a constant value: clocks could be shifted by an hour or more on some dates. Use Instant to perform reliable time arithmetic.

Samples

import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.random.*
import kotlin.test.*
fun main() { 
   //sampleStart 
   // Converting a LocalTime to the number of milliseconds since the start of the day and back
val millisecondsInDay = 24 * 60 * 60 * 1_000
val randomNumberOfMilliseconds = Random.nextInt(millisecondsInDay)
val time = LocalTime.fromMillisecondOfDay(randomNumberOfMilliseconds)
check(time.toMillisecondOfDay() == randomNumberOfMilliseconds)
check(time.nanosecond % 1_000_000 == 0) // sub-millisecond part is zero 
   //sampleEnd
}
actual fun fromMillisecondOfDay(millisecondOfDay: Int): LocalTime(source)
actual fun fromMillisecondOfDay(millisecondOfDay: Int): LocalTime(source)