toString

actual open override fun toString(): String(source)
expect open override fun toString(): String(source)

Converts this time value to the extended ISO 8601 string representation.

For readability, if the time represents a round minute (without seconds or fractional seconds), the string representation will not include seconds. Also, fractions of seconds will add trailing zeros to the fractional part until the number of digits after the dot is a multiple of three.

Examples of output:

  • 18:43

  • 18:43:00

  • 18:43:00.500

  • 18:43:00.123456789

See also

for a very similar format. The difference is that Formats.ISO will always include seconds, even if they are zero, and will not add trailing zeros to the fractional part of the second for readability.

for the dual operation: obtaining LocalTime from a string.

for formatting using a custom format.

Samples

import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.random.*
import kotlin.test.*
fun main() { 
   //sampleStart 
   // Converting a LocalTime to a human-readable string
check(LocalTime(hour = 8, minute = 30).toString() == "08:30")
check(LocalTime(hour = 8, minute = 30, second = 15).toString() == "08:30:15")
check(LocalTime(hour = 8, minute = 30, second = 0, nanosecond = 120000000).toString() == "08:30:00.120") 
   //sampleEnd
}
actual open override fun toString(): String(source)
actual open override fun toString(): String(source)