https://kotlinlang.org logo
Join Slack
Powered by
# kotlinx-datetime
  • c

    CLOVIS

    12/17/2024, 2:33 PM
    I have a specific
    Instant
    . For a given
    TimeZone
    (thus I can get a
    LocalDateTime
    ), I want to know the very first existing hour of the next day in that timezone. For example, if I have 23h47 december 17th in France, I want 00h00 december 18th. If 00h00 december 18th doesn't exist for whatever reason, I want the very next time that happens in that timezone, however later it happens to be. How can I represent this?
    d
    d
    s
    • 4
    • 12
  • j

    Joel Denke

    12/17/2024, 7:10 PM
    yyyy-MM-dd'T'HHmmss'Z The default formatters or adapters for kotlinx serialization doesnt understand this UTC format used. I often fall back to Instant but ideally I want LocalDateTime. How do I do this the right way if any? I dont like using Instant and want avoid do custom parser. Want standard iso parsers from kotlinx only ideally.
    d
    c
    • 3
    • 21
  • m

    Matas Lauzadis

    12/19/2024, 11:13 PM
    How can I have my custom DateTimeFormat consume a string but return a different value during parsing? I'm trying to add support for leap seconds (
    23:59:60
    ) which needs to subtract one second (becoming
    23:59:59
    ). I have a function:
    private fun WithTime.secondOrleapSecond() = alternativeParsing({ second() }) { chars("60") }
    . This can parse the leap seconds without crashing, but (understandably) returns
    23:59:0
    . How can I set
    seconds = 59
    in this case? I found a GitHub issue about leap seconds, there was a hint of a solution but none offered.
    d
    • 2
    • 2
  • r

    russhwolf

    01/12/2025, 1:17 AM
    I've seen this question asked before but I don't think I've seen an official answer. Is it intended that
    TimeZone.UTC
    is not equivalent to
    TimeZone.of("UTC")
    ? That's incredibly unintuitive.
    k
    d
    • 3
    • 11
  • k

    kevin.cianfarini

    01/15/2025, 7:23 PM
    Perhaps relevant to crosspost this here, too: https://kotlinlang.slack.com/archives/C0B8Q383C/p1736968593656649
  • r

    rob42

    01/17/2025, 3:26 PM
    I have an Instant, and I want to format that to a localized month+year string. So in English, "January 2025", or in Korean "2025년 1월" etc... I know the user's locale, so no magic involved. Feels like this should be very achievable, but can't find any documentation/resources on how to do so in Kotlin multiplatform?
    d
    • 2
    • 5
  • d

    dave08

    01/20/2025, 11:53 AM
    If I want to truncate an Instant to only include up till the hour's start (w/o minutes/seconds/etc...) what's the simplest/most ideomatic way to do this in KotlinX Datetime?
    d
    k
    c
    • 4
    • 33
  • c

    CLOVIS

    02/05/2025, 4:58 PM
    The README says:
    DatePeriod
    is a subclass of
    DateTimePeriod
    with zero time components, it represents a difference between two LocalDate values decomposed into date units.
    Ok, but, how?
    LocalDate
    doesn't have a
    -
    operator 🤔
    k
    d
    • 3
    • 5
  • c

    CLOVIS

    02/05/2025, 5:05 PM
    Is there a reason
    UtcOffset
    doesn't internally rely on
    Duration
    ? Looking at the code, my guess is that it was to rely on Java's implementation?
    d
    • 2
    • 3
  • h

    hfhbd

    02/06/2025, 9:15 AM
    Do you have any plans to release a pre release using 2.1.20-Beta2 to use the stdlib Instant class?
    d
    j
    • 3
    • 5
  • d

    Dmitry Khalanskiy [JB]

    02/10/2025, 3:41 PM
    📣 kotlinx-datetime 0.6.2 is here, and with it, Wasm/WASI support, along with some small tweaks and fixes! Full changelog: https://github.com/Kotlin/kotlinx-datetime/releases/tag/v0.6.2
    🎉 12
    b
    • 2
    • 5
  • d

    dawidhyzy

    02/17/2025, 8:32 AM
    Google just introduced a new API to provide a trusted time source https://android-developers.googleblog.com/2025/02/trustedtime-api-introducing-reliable-approach-to-time-keeping-for-apps.html?m=1. Is there a way to use it with kotlinx-datetime?
    s
    t
    +3
    • 6
    • 18
  • p

    peekandpoke

    03/03/2025, 9:30 AM
    When can we expect support for Kotlin 2.1 on kotlinx datetime? Not having this holds us back form upgrading all our multiplatfrom projects to Kotlin 2.x. So this is very much needed and will be highly appreciated! Any timeline in sight? @Dmitry Khalanskiy [JB]
    solved 1
    d
    • 2
    • 24
  • c

    curioustechizen

    03/17/2025, 1:56 PM
    Do I understand correctly that the formatting APIs introduced in kotlinx-datetime v0.6 do not format according to the locale? For example they don't display month names or week names according to the current locale, is that correct?
    👌 2
    k
    • 2
    • 2
  • s

    Stylianos Gakis

    03/24/2025, 4:05 PM
    If I get a String like for example
    Copy code
    2025-03-24T08:00:00.000001Z
    Which indicates that it's in UTC time, hence the
    Z
    afaik But I may get an instant which is not
    Z
    there, but some other timezone too Is there a way for me to turn it into a LocalDateTime, but using whatever time-zone the string itself already came in? So I want to do
    Copy code
    Instant
     .parse("2025-03-24T08:00:00.000001Z")
     .toLocalDateTime(???)
    But not sure what I should do for timezone. The use-case is that my server is giving me a timestamp, and I want to show the date only as-is, so whatever the server had decided already. So if you are in different parts of the world you do not get different results (if I used
    TimeZone.currentSystemDefault()
    ) but I also don't want to just default to UTC and potentially change the date that I show if the timestamp was not in UTC.
    d
    c
    +3
    • 6
    • 17
  • m

    Manuel Lorenzo

    03/28/2025, 8:06 PM
    Hello everybody! How can I get the current LocalDateTime in Swift using KMP? All I have in Swift for now is something like
    Kotlinx_datetimeLocalDateTime
    c
    • 2
    • 2
  • r

    Robert Jaros

    04/14/2025, 12:29 PM
    When using
    kotlinx-datetime
    on Kotlin/JS on Windows I have a strange problem with casing. There is a webpack warning and the library is not working correctly (
    ClassCastException
    is thrown):
    Copy code
    There are multiple modules with names that only differ in casing.
    This can lead to unexpected behavior when compiling on a filesystem with other case-semantic.
    Use equal casing. Compare these module identifiers:
    
        javascript/esm|C:\Users\kpadarz\Desktop\Wykaz\wykaz2\wykaz\build\js\packages\wykaz\kotlin\Kotlin-DateTime-library-kotlinx-datetime\kotlinx\datetime\serializers\LocalTimeSerializers.mjs Used by 1 module(s), i. e. javascript/esm|C:\Users\kpadarz\Desktop\Wykaz\wykaz2\wykaz\build\js\packages\wykaz\kotlin\Kotlin-DateTime-library-kotlinx-datetime\kotlinx\datetime\localtime.mjs
        javascript/esm|C:\Users\kpadarz\Desktop\Wykaz\wykaz2\wykaz\build\js\packages\wykaz\kotlin\kotlin-datetime-library-kotlinx-datetime\kotlinx\datetime\serializers\LocalTimeSerializers.mjs Used by 1 module(s), i. e. javascript/esm|C:\Users\kpadarz\Desktop\Wykaz\wykaz2\wykaz\build\js\packages\wykaz\kotlin\kotlin-datetime-library-kotlinx-datetime\kotlinx\datetime\localtime.mjs
    d
    • 2
    • 7
  • k

    kevin.cianfarini

    04/29/2025, 1:20 PM
    I find myself somewhat frequently doing:
    Copy code
    val min = LocalTime(hour = 0, minute = 0, second = 0, nanosecond = 0)
    val max = LocalTime(hour = 23, minute = 59, second = 59, nanosecond = 999_999_999)
    Would there be any interest in accepting a PR that specifies
    LocalTime.MIN
    and
    LocalTime.MAX
    like both Instant and LocalDateTime have?
    d
    • 2
    • 2
  • k

    kevin.cianfarini

    04/29/2025, 3:19 PM
    I’m wondering if any of the kotlinx-datetime maintainers have read Jesse’s blog post titled Identifiers aren’t services in which he argues in part that
    kotlinx.datetime.TimeZone
    shouldn’t query the underlying database from the tzdb entry when calling
    TimeZone.of(String)
    . Do you have thoughts?
    c
    j
    +3
    • 6
    • 109
  • k

    kevin.cianfarini

    05/07/2025, 6:43 PM
    I maintain a (not yet stable) library that exposes extension functions on
    kotlinx.datetime.Clock
    . I suspect I should move those to
    kotlin.time.Clock
    ? When is
    kotlinx.datetime.Clock
    planned to be removed?
    c
    • 2
    • 6
  • s

    Smoothie

    05/26/2025, 9:22 AM
    Hey, DayOfWeek in Android is typealiased to java.time, so it require API26 or there is a built in desugaring ?
    j
    • 2
    • 2
  • d

    Dmitry Khalanskiy [JB]

    06/24/2025, 2:53 PM
    📣
    kotlinx-datetime
    0.7.0 is here! •
    Instant
    and
    Clock
    were moved to the standard library and are no longer part of
    kotlinx-datetime
    . Please follow https://github.com/Kotlin/kotlinx-datetime?tab=readme-ov-file#deprecation-of-instant if you encounter problems because of that. •
    LocalDateRange
    , a range of date values, was added. •
    YearMonth
    and
    YearMonthRange
    were added. • Serializers that can be parameterized with a
    DateTimeFormat
    were added. • Most entities in the library are
    java.io.Serializable
    now. • Other changes. The full changelog is available here: https://github.com/Kotlin/kotlinx-datetime/releases/tag/v0.7.0
    ❤️ 5
    🎉 3
    kodee happy 1
    K 18
    kodee frustrated 1
    f
    j
    +4
    • 7
    • 15
  • d

    Dmitry Khalanskiy [JB]

    06/30/2025, 11:46 AM
    If you are 1. Not using libraries that themselves depend on
    kotlinx-datetime
    0.6.2 or earlier, and are also 2. Planning on upgrading to
    kotlinx-datetime
    0.7.0, but haven't yet, then you are advised to wait until 0.7.1 comes out in the next few days. 0.7.0 is missing some migration assistance, namely the deprecated-with-warning type aliases
    kotlinx.datetime.Instant = kotlin.time.Instant
    and
    kotlinx.datetime.Clock = kotlin.time.Clock
    (https://github.com/Kotlin/kotlinx-datetime/pull/540/commits/f829958a1bcbe7b24a11a91519cf57aaf3daa74b). Without them, your client code will not compile until you replace the usages manually, whereas with them, you will be able to proceed at your own pace (if you are not using libraries that themselves depend on
    kotlinx.datetime.Instant
    ) or even perform automatic replacement with the help of an IDE. This is a glaring omission that I made when publishing the release, and I am sorry about that. The type aliases in 0.7.0 were planned from the beginning, but due to my oversight, were missing from the release.
    👍🏽 1
    thank you color 4
    👍 8
    j
    e
    r
    • 4
    • 10
  • d

    Dmitry Khalanskiy [JB]

    07/07/2025, 6:04 PM
    📣
    kotlinx-datetime
    0.7.1 is here, providing a more convenient migration path to
    kotlin.time.Instant
    ! https://github.com/Kotlin/kotlinx-datetime/releases/tag/v0.7.1
    🎉 10
    j
    d
    b
    • 4
    • 8
  • u

    ursus

    07/13/2025, 1:45 AM
    Are prebuilt auto-internationalized local date time formatters coming (like
    java.time
    has)?
    d
    • 2
    • 1
  • c

    curioustechizen

    07/18/2025, 1:25 PM
    If I understand correctly,
    kotlin.time.Instant
    and
    kotlin.time.Clock
    were introduced in Kotlin 2.1.20 Then, kotlinx.serialization added support for these 2 types in v1.9.0, but that requires Kotlin 2.2 What are my options if I want to stay on Kotlin 2.1.20 and want to serialize kotlin.time.Instant types? Is the
    compat
    artifact useful for this situation?
    j
    h
    n
    • 4
    • 5
  • c

    curioustechizen

    07/21/2025, 11:05 AM
    kotlinx.datetime.Instant
    would be visible to iOS as
    Kotlinx_datetimeInstant
    Since it is moved to the stdlib, what should it be exported as?
    Kotlin_timeInstant
    is not found, neither is just Instant.
    d
    • 2
    • 3
  • d

    Dmitry Khalanskiy [JB]

    07/30/2025, 2:23 PM
    📣 Hi everyone! A heads-up: we are planning to remove the
    @Serializable
    annotation from
    TimeZone
    and
    FixedOffsetTimeZone
    in the future and deprecate the serializers for these classes. Please restructure your code to send and receive the timezone identifier (
    timeZone.id
    , converted back to the timezone with
    TimeZone.of(id)
    ) instead of the timezone itself. The reason for this change is that the timezone database used in the code performing the deserialization can be different from the one that was used for serialization. This may even lead to crashes if the deserializing side does not know the serialized timezone identifier. The explicit need to call
    TimeZone.of
    on the deserialization result gives a more controlled environment for handling the failure and demonstrates the risk better.
    👀 3
    thank you color 9
  • f

    Filipp Zhinkin

    08/15/2025, 5:41 PM
    Hey folks! We're thinking about
    kotlin.time.Instant
    and
    kotlin.time.Clock
    stabilization in Kotlin
    2.3
    , so if there was anything with them that you wanted to change, it's time to let us know: https://kotlinlang.slack.com/archives/C0B8Q383C/p1755279531599069
    K 9
    a
    • 2
    • 2
  • e

    Emre

    09/09/2025, 10:13 PM
    Does anyone have any suggestions for dealing with errors like this? > org.apache.fury.exception.InsecureException: class kotlin.time.InstantSerialized is not registered... Basically, a serialization library wants me to register
    InstantSerialized::class.java
    because I use
    kotlin.time.Instant
    in a data class but I can't because
    InstantSerialized
    is private. I did not have this problem with
    kotlinx-datetime
    .
    d
    • 2
    • 5