Is there built in Kotlin function to use `System.c...
# multiplatform
a
Is there built in Kotlin function to use
System.currentTimeInMillis()
in Kotlin? If not what should be the fallback for native, jvm(desktop) and IOS?
m
You can use:
Clock.System.now()
in https://github.com/Kotlin/kotlinx-datetime
a
Thanks will look
This will required coreDesugaring in android for 23 api above. Right? Found it:
If you target Android devices running *below API 26*, you need to use Android Gradle plugin 4.0 or newer and enable core library desugaring.
m
If you want to avoid this, you can use expect/actual and use java datetime for android and jvm and use kotlinx-datetime for the other targets
a
For all expect actual is this expected to make top level function? I am concerned that all my function will pollute the global namespace
m
You can have an expect actual with objects and have some methods inside it.
Like this:
Copy code
expect object DateTime {
    fun currentTimeInMillis(): Long
}
thank you color 1
h
What exactly do you want to achieve? If you need to measure some function call, you can also use measureTime
a
Just wanted to insert a entity into room with creation time in ms
h
Then you can also add a default value to your column: CURRENT_TIMESTAMP