Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current unixtime on Kotlin standard library (multiplatform)

I have a Kotlin multiplatform project, and I would like to get the current unixtime in the shared code.

How do you do that in the Kotlin standard library?

like image 583
Daniele B Avatar asked Oct 07 '20 19:10

Daniele B


People also ask

Is kotlin multiplatform stable?

Since Kotlin Multiplatform Mobile is now in Beta, we are working on stabilizing the corresponding plugin for Android Studio and will be regularly releasing new versions that include new features, improvements, and bug fixes.

When was kotlin multiplatform released?

Kotlin multiplatform is a feature released in 2017 with Kotlin 1.2. This feature allows you to write the same code on multiple platforms directly, it focuses on cross-platform app development.

What is kotlin multiplatform mobile?

What is Kotlin Multiplatform Mobile? Kotlin Multiplatform Mobile (KMM) is an SDK for cross-platform mobile development. You can develop multiplatform mobile applications and share parts of your applications between Android and iOS, such as core layers, business logic, presentation logic, and more.


1 Answers

It's possible to use the experimental Kotlin datetime library, currently at version 0.1.0

val nowUnixtime = Clock.System.now().epochSeconds

More info here: https://github.com/Kotlin/kotlinx-datetime

like image 80
Daniele B Avatar answered Oct 16 '22 01:10

Daniele B