toString

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

Converts this instant to the ISO 8601 string representation, for example, 2023-01-02T23:40:57.120Z.

The representation uses the UTC-SLS time scale instead of UTC. In practice, this means that leap second handling will not be readjusted to the UTC. Leap seconds will not be added or skipped, so it is impossible to acquire a string where the component for seconds is 60, and for any day, it's possible to observe 23:59:59.

See also

for a very similar format. The difference is that DateTimeComponents.Formats.ISO_DATE_TIME_OFFSET will not add trailing zeros for readability to the fractional part of the second.

Samples

import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.random.*
import kotlin.test.*
import kotlin.time.Duration.Companion.hours
fun main() { 
   //sampleStart 
   // Converting an Instant to a string
check(Instant.fromEpochSeconds(0).toString() == "1970-01-01T00:00:00Z") 
   //sampleEnd
}
actual open override fun toString(): String(source)
actual open override fun toString(): String(source)