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

    CLOVIS

    08/21/2024, 2:18 PM
    In the documentation of
    LocalDate.atTime
    :
    For finding an instant that corresponds to the start of a date in a particular time zone, consider using LocalDate.atStartOfDayIn function because a day does not always start at the fixed time 00000.
    Out of curiosity, does that regularly happen? If it was a one-time thing, I'm curious when and why
    k
    d
    • 3
    • 5
  • k

    kevin.cianfarini

    09/09/2024, 3:16 PM
    Hi, I just want to share that I’ve published version 0.3.0 of Cardiologist which accounts for Clock drift now 🙂 Let me know what you think!
  • m

    Mark

    09/10/2024, 2:06 PM
    Is there a way to format a
    LocalDate
    without showing the year? Equivalent of Android’s
    DateUtils.FORMAT_NO_YEAR
    d
    k
    • 3
    • 6
  • o

    Oliver.O

    09/28/2024, 9:19 PM
    Is there a publicly accessible repo with dev builds of kotlinx-datetime? I'm interested in the new
    wasmWasi
    target support.
    d
    • 2
    • 2
  • c

    CLOVIS

    10/15/2024, 7:54 PM
    Is this normal?
    Copy code
    e: KLIB resolver: Could not find "org.jetbrains.kotlinx:kotlinx-datetime-cinterop-date" in [/…/pedestal, /…/.konan/klib, /…/.konan/kotlin-native-prebuilt-linux-x86_64-2.0.0/klib/common, /…/.konan/kotlin-native-prebuilt-linux-x86_64-2.0.0/klib/platform/linux_x64]
    It just started happening on an existing project. Kotlin 2.0.0 KotlinX.Datetime 0.6.0
    d
    • 2
    • 6
  • r

    Raphael TEYSSANDIER

    10/23/2024, 9:09 AM
    Hello, does format ISO8601:2004 is supported ?
    d
    • 2
    • 9
  • a

    Alexandru Gheorghe

    11/21/2024, 2:50 PM
    Hi all. I'm trying to understand an issue: I take local time and with
    .toInstant(TimeZone.UTC)
    I'm converting it to UTC. I noticed that the time is kept the same. I was expecting it to change to a time in UTC timezone. This creates a disparity between the user creating data in their timezone and expecting it to show up with the same time (when converted back from UTC into system's timezone) however this is not the case as the time is not adjusted. Am I missing something?
    s
    m
    +3
    • 6
    • 20
  • d

    Daniel Pitts

    12/05/2024, 3:07 AM
    I want to create an instance of
    kotlinx.datetime.format.DateTimeFormat
    which will correctly parse "an iCalendar format DATE-TIME value in UTC". For example
    19000101T000000Z
    . ChatGPT and Github Copilot are eager to tell me how to do it with Java, but completely lost with Kotlinx datetime.
    e
    d
    • 3
    • 10
  • a

    Alexandru Gheorghe

    12/11/2024, 3:47 PM
    Hi all. I'm trying to convert an instant from local time zone (e.g. America/New_York) to UTC (with offset) which should be (at this moment in time) +5 hours. When I'm trying to calculate offset in time zone UTC I get no change (printing it shows "Z"). How can I convert from local time zone adjusted to UTC where the delta is taken into account properly? It seems right now, whatever the instant is it will just be used as is but with UTC with no datetime change.
    s
    d
    • 3
    • 4
  • a

    Alexandru Gheorghe

    12/14/2024, 10:47 AM
    Hi folks. Any ideas as to why
    Clock.System.now().toEpochMilliseconds()
    returns time in UTC rather than local time? What was the rationale behind this behaviour?
    h
    c
    • 3
    • 2
  • 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
    🎉 11
    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
    +2
    • 5
    • 16
  • 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