Spec-Zone.ru › Kotlin 2

toString

kotlin-stdlib/kotlin.time/Instant/toString

Начиная с Kotlin: 2.3

open override fun toString(): String

Преобразует этот момент времени в строковое представление ISO 8601, например, 2023-01-02T23:40:57.120Z.

В представлении используется шкала времени UTC-SLS вместо UTC. На практике это означает, что обработка високосных секунд не будет скорректирована в соответствии с UTC. Високосные секунды не будут добавляться или пропускаться, поэтому невозможно получить строку, в которой компонент секунд равен 60; для любого дня можно наблюдать время 23:59:59.

См. также

parse

Примеры

import kotlin.test.*
import kotlin.time.*
import kotlin.time.Duration.Companion.hours
import kotlin.time.Duration.Companion.nanoseconds
import kotlin.time.Duration.Companion.seconds

fun main() { 
   //sampleStart 
   // The string representation of the current instant in ISO 8601 format.
val currentInstant = Clock.System.now()
println(currentInstant.toString())
// The string representation of the Unix epoch.
val unixEpochInstant = Instant.fromEpochSeconds(0)
println(unixEpochInstant.toString()) // 1970-01-01T00:00:00Z
// The string representation of an instant.
val instant = Instant.fromEpochMilliseconds(1_000_000_000_123)
println(instant.toString()) // 2001-09-09T01:46:40.123Z 
   //sampleEnd
}

© 2010–2026 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.time/-instant/to-string.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API