https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
kotlinx-datetime
  • p

    Paul Woitaschek

    06/27/2021, 10:24 AM
    What's the plan for more time types? I consistently find myself in the situation of creating new time types myself like LocalTime, MonthDay etc. As a full replacement for the java time operations the library feels really half baked.
    ➕ 4
    m
    • 2
    • 1
  • n

    Nikita Khlebushkin

    07/16/2021, 6:12 PM
    Hello! I am having some strange bug:
    java.lang.NoSuchFieldError: No field MIN of type Lj$/time/Instant; in class Lj$/time/Instant; or its superclasses (declaration of 'j$.time.Instant' appears in /data/app/my.app-Rumayx4kmF4yH-665uzCBw==/base.apk!classes2.dex)
            at kotlinx.datetime.Instant.<clinit>(Instant.kt:96)
            at kotlinx.datetime.Clock$System.now(Clock.kt:17)
    The line where it happens:
    val fetchStartEpoch = clock.now().toEpochMilliseconds()
    I tried with datetime 0.1.1 and 0.2.1, same result. Another interesting detail is that it only happened after I added
    compileOptions {
            isCoreLibraryDesugaringEnabled = true
        }
    I had to add it after the library started to crash on Android 26. Any clues how I can deal with it?
    • 1
    • 2
  • i

    Imran/Malic

    08/22/2021, 2:10 PM
    Hi all, is UtcOffset the equivalent of
    OffsetDateTime
    ? And is there a snapshot release somewhere?
    i
    • 2
    • 6
  • n

    Nick

    08/26/2021, 9:16 PM
    I’d like to convert an ISO string to a readable format the end user would understand. I can’t seem to find how to do it with Date-Time. Am I missing something? This would go in a ViewModel, which I intend on making multiplatform.
    i
    • 2
    • 1
  • d

    Desmond van der Meer

    08/31/2021, 6:39 AM
    Hi, I'm having a problem with my unit tests when running them in JavaScript. I'm using
    TimeZone.of("Europe/Amsterdam")
    , but that is not recognized during unit tests in JS (a
    IllegalTimeZoneException
    is thrown), presumably because it can't find some asset/resource with time zone information? Is this a known issue, does anyone know how to solve this? The time zone can be found without problem when I run the code normally
    i
    • 2
    • 2
  • y

    Yang

    09/08/2021, 10:52 AM
    👋 are there plans to add Apple silicon targets? https://github.com/Kotlin/kotlinx-datetime/issues/141
    ➕ 7
    p
    i
    t
    • 4
    • 5
  • z

    Zhiqiang Bian

    09/28/2021, 6:48 PM
    Hi all! I am using
    kotlinx-datetime
    for KMM development. In my
    androidApp/build.gradle.kts
    , if I set
    debuggable
    to
    true
    , then it works well. But if I set
    debuggable
    to
    false
    (for release), the app will crash immediately when executing any
    kotlinx-datetime
    code (in common folder). Does anyone know the reason?
    ✅ 1
    l
    • 2
    • 4
  • c

    chi

    12/07/2021, 8:07 PM
    Hello all, is there a way to directly parse a date string in this format; "MM/dd/yyyy HH🇲🇲ss" using Kotlin Date time?
    LocalDateTime
    or
    Instant
    string parsing methods fail
    m
    • 2
    • 3
  • j

    jim

    12/13/2021, 9:36 AM
    Hey!  I'm trying to add https://github.com/Kotlin/kotlinx-datetime to my kotlinjs project, but I'm getting errors related to joda-timezone.  I've added 
    implementation(npm("@js-joda/timezone", "2.3.0"))
     to my 
    jsMain
     dependencies, and also added a block to the beginning of my 
    Main.kt
     file:
    @JsModule("@js-joda/timezone")
    @JsNonModule
    external object JsJodaTimeZoneModule
    
    private val jsJodaTz = JsJodaTimeZoneModule
    I build with 
    jsBrowserDistribution
    but if I look at the build output javascript file, the very first few lines are:
    (function (root, factory) {
      if (typeof define === 'function' && define.amd)
        define(['exports', '@js-joda/timezone', '@js-joda/core'], factory);
      else if (typeof exports === 'object')
        factory(module.exports, require('@js-joda/timezone'), require('@js-joda/core'));
      else {
        if (typeof JsJodaTimeZoneModule === 'undefined') {
          throw new Error("Error loading module 'turntaker-js'. Its dependency '@js-joda/timezone' was not found. Please, check whether '@js-joda/timezone' is loaded prior to 'turntaker-js'.");
        }if (typeof this['@js-joda/core'] === 'undefined') {
          throw new Error("Error loading module 'turntaker-js'. Its dependency '@js-joda/core' was not found. Please, check whether '@js-joda/core' is loaded prior to 'turntaker-js'.");
        }root['turntaker-js'] = factory(typeof this['turntaker-js'] === 'undefined' ? {} : this['turntaker-js'], JsJodaTimeZoneModule, this['@js-joda/core']);
      }
    }(this, function (_, JsJodaTimeZoneModule, $module$_js_joda_core) {
    which would seem to imply that the JsJodaTimeZoneModule is not being included, or certainly not being included prior to the check running
    d
    d
    s
    • 4
    • 8
  • t

    Tristan

    12/15/2021, 6:59 PM
    Hello, I have a Kotlin/JS project only (not multiplatform) where I import the library like this:
    plugins {
        kotlin("js") version "1.5.10"
    }
    
    repositories {
        mavenCentral()
    }
    
    kotlin {
        js(IR) {
            binaries.executable()
            browser()
        }
    
        sourceSets {
            val main by getting {
                dependencies {
                    implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.3.1")
                }
            }
        }
    }
    But when I try to compile, I get this error
    > Task :compileKotlinJs FAILED
    e: java.lang.AssertionError: Built-in class kotlin.Unit is not found
    How should I import this? Thanks for your help.
    r
    • 2
    • 3
  • p

    ptsiogas

    01/24/2022, 3:42 PM
    Hi there, it’s been over a year since this post. Is there any way to do what is being described?
    👀 1
    • 1
    • 1
  • j

    jean

    01/26/2022, 10:21 AM
    Jean Tuffier  [11:15 AM] Is there a way to convert a string from utc time zone like this 
    2021-11-29T23:00:00.000+0000
     to it’s equivalent in another time zone? I tried this :
    internal fun String.localDateTime(): LocalDateTime = Instant.parseWithBasicOffset(this) //parseWithBasicOffset is a custom parse due to time zone written without ":" 
        .toLocalDateTime(TimeZone.currentSystemDefault())
    but
    myString.localDateTime().toString()
    returns
    2021-11-30T00:00
    the date is correct but I lost the time zone there, which I need for further processing. So my question is : how do I go from
    2021-11-29T23:00:00.000+0000
    to
    2021-11-30T00:00:00.000+0100
    (or eventually
    +01:00
    )
    d
    i
    • 3
    • 4
  • j

    jean

    02/14/2022, 2:20 PM
    let’s say I want the value of “yesterday”, I can do something like this :
    Clock.System.now()
        .minus(1, DateTimeUnit.DAY, TimeZone.of(timeZoneId))
    I just realized that
    now
    is also relative to my personal timezone, isn’t? I could ask for the now value of japan for example, which is way different that mine. So why doesn’t
    now
    take a Timezone parameter? Or did I miss something?
    d
    d
    i
    • 4
    • 13
  • b

    brabo-hi

    02/17/2022, 6:56 AM
    Hi all i have received a weird crash error when invoking
    Clock.System.now()
    Fatal Exception: java.lang.NoClassDefFoundError
    kotlinx.datetime.Instant
    kotlinx.datetime.Clock$System.now (Clock.kt:17)
    l
    m
    • 3
    • 7
  • m

    mkrussel

    02/24/2022, 8:05 PM
    Why are all the releases listed on GItHub prereleases? It makes it seem like they should not be used.
    j
    d
    • 3
    • 3
  • a

    andylamax

    03/23/2022, 11:47 AM
    Can we please Mark
    LocalDate
    ,
    LocalDateTime
    and
    Instant
    with
    @JsExport
    , At the moment, we can't use it
    d
    • 2
    • 3
  • k

    Konstantin Zolotov

    04/22/2022, 2:50 PM
    Hello there! Probably stupid question, but search doesn’t give me an answer unfortunately. Is there a simple way to clamp
    LocalDateTime
    to the beginning of the day? So far I see only the option
    localDateTime.date.atTime(0, 0)
    , is this the way? :mandalorian:
    i
    • 2
    • 2
  • p

    Paul Woitaschek

    05/05/2022, 9:31 AM
    What’s the motivation that datetime 0.3.3 now targets a beta kotlin release? This causes bugs from the kotlin beta preventing us from updating kotlinx date time
    > Task :uniqueId:linkDebugTestIosSimulatorArm64 FAILED
    e: Compilation failed: Unexpected IrType kind: KIND_NOT_SET
    
     * Source files: 
     * Compiler version info: Konan: 1.6.21 / Kotlin: 1.6.21
     * Output kind: STATIC_CACHE
    
    e: java.lang.IllegalStateException: Unexpected IrType kind: KIND_NOT_SET
    👀 1
    🤷‍♂️ 1
    i
    • 2
    • 5
  • d

    Dmitry Khalanskiy [JB]

    06/24/2022, 1:49 PM
    📣 📣 📣 kotlinx.datetime 0.4.0 is here! The highlight:
    LocalTime
    , a representation of time-of-day, is now provided (a contribution by https://github.com/bishiboosh).
    ❤️ 3
    👍 6
    j
    i
    • 3
    • 2
  • a

    Akram Bensalem

    06/28/2022, 11:28 AM
    Hello, The current time is always with "06" minutes !!! Is this a bug ?
    ✅ 1
    h
    • 2
    • 2
  • a

    Akram Bensalem

    07/19/2022, 1:36 PM
    How to specify the language of the return value of this:
    val date = DateTimeFormatter
        .ofPattern(pattern)
        .withZone(zoneId)
        .format(date.toJavaInstant())
    I don't want it to return the default language of the system
    m
    • 2
    • 1
  • k

    kevin.cianfarini

    07/27/2022, 4:38 PM
    is there any reason
    Clock
    isn’t a
    fun interface
    ?
    p
    • 2
    • 1
  • h

    humblehacker

    08/12/2022, 8:52 PM
    Given a
    LocalDate
    , how do I format it as a localized string?
    java.time.LocalDate()
    has a
    format()
    method, but the kotlinx version doesn't, and so far my google searches are unsuccessful.
    m
    j
    • 3
    • 4
  • k

    kevin.cianfarini

    08/17/2022, 1:22 PM
    Should serializing a FixedOffsetTimeZone like
    TimeZone.UTC
    just yield a
    'Z'
    ? This was violating a backend contract we have and took me by surprise. Doing
    TimeZone.of("UTC")
    fixed this.
    • 1
    • 1
  • a

    andylamax

    08/24/2022, 7:43 AM
    Is the team accepting pull requests?? I wish to submit one. But I see here there are un merged pull requests which where submitted since July 2021. Is it worth it? or just a waster of time?
    i
    • 2
    • 2
  • v

    Vsevolod Tolstopyatov [JB]

    10/19/2022, 4:15 PM
    We’ve initiated the discussion about zoned date times: https://github.com/Kotlin/kotlinx-datetime/discussions/237 Feel free to participate!
    j
    d
    t
    • 4
    • 4
  • d

    Dragos Rachieru

    10/24/2022, 11:55 AM
    Hello, how can I get units from an instant? Like
    instant.get(DateTimeUnit.HOUR)
    ?
    d
    • 2
    • 2
  • r

    romainbsl

    11/14/2022, 9:39 AM
    Hi, any idea why embedded linuxes are not supported by KX DateTime ? https://github.com/Kotlin/kotlinx-datetime/issues/165
    d
    • 2
    • 2
  • f

    farmerbb

    11/23/2022, 8:24 PM
    Does kotlinx.datetime have a multiplatform equivalent for
    java.time.format.DateTimeFormatter
    ?
    m
    j
    d
    • 4
    • 7
  • s

    Stylianos Gakis

    12/14/2022, 12:27 PM
    Does the library offer some way to run tests with a test instance of the
    Clock
    interface? Basically one where I can control the time passed myself. Basically I’m trying to run a test where two classes receive a Clock instance, current just passing in Clock.System in, but then
    now()
    resolves two different times but I want for the test for them to resolve on the same now. I can probably make my own Clock instance where I just always return the same Instance, but just checking if there’s some existing artifact which gives a nice test Clock instance with some more control than what I’d do myself.
    d
    h
    • 3
    • 4
Powered by Linen
Title
s

Stylianos Gakis

12/14/2022, 12:27 PM
Does the library offer some way to run tests with a test instance of the
Clock
interface? Basically one where I can control the time passed myself. Basically I’m trying to run a test where two classes receive a Clock instance, current just passing in Clock.System in, but then
now()
resolves two different times but I want for the test for them to resolve on the same now. I can probably make my own Clock instance where I just always return the same Instance, but just checking if there’s some existing artifact which gives a nice test Clock instance with some more control than what I’d do myself.
d

Dmitry Khalanskiy [JB]

12/14/2022, 12:33 PM
Nothing official is provided, but this probably should be fairly straightforward to implement, no?
public class TestClock: Clock {
    private var now: Instant = Clock.System.now()

    public fun advanceTimeBy(duration: Duration) {
        require(duration > Duration.ZERO)
        now += duration
    }

    override fun now(): Instant = now
}
s

Stylianos Gakis

12/14/2022, 12:39 PM
Yeap this is pretty much what I had written myself too (minus the require step, which is smart 😅) I was simply wondering if there was something somewhere that I missed, but I understand why there’s not atm. Thanks for the help 🤗
h

hfhbd

12/14/2022, 2:58 PM
Alternative if you want to sync your clock with
runTest
and its `testTimeSource`:
@ExperimentalTime
 public fun TimeSource.toClock(offset: Instant = Instant.fromEpochSeconds(0)): Clock = object : Clock {
     private val startMark: TimeMark = markNow()
     override fun now() = offset + startMark.elapsedNow()
 }
s

Stylianos Gakis

12/14/2022, 3:01 PM
Ohh interesting yeah I might need that in the future, thanks!
View count: 6