from Second Of Day
Constructs a LocalTime that represents the specified number of seconds since the start of a calendar day. The fractional parts of the second will be zero.
See also
Throws
if secondOfDay is outside the 0 until 86400
range, with 86400 being the number of seconds in a calendar day.
It is incorrect to pass to this function the number of seconds that have physically elapsed since the start of the day. The reason is that, due to the daylight-saving-time transitions, the number of seconds 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 seconds since the start of the day and back
val secondsInDay = 24 * 60 * 60
val randomNumberOfSeconds = Random.nextInt(secondsInDay)
val time = LocalTime.fromSecondOfDay(randomNumberOfSeconds)
check(time.toSecondOfDay() == randomNumberOfSeconds)
check(time.nanosecond == 0) // sub-second part is zero
//sampleEnd
}