Aleksandr Wake
Aleksandr Wake

Reputation: 91

Get current time in Unix Timestamp Kotlin?

How can I get current time in Unix Timestamp format in kotlin as integer?

Upvotes: 7

Views: 10012

Answers (1)

Rohen Giralt
Rohen Giralt

Reputation: 427

If you're using Kotlin on the JVM or Android, it's as simple as

val unixTime = System.currentTimeMillis()

for the unix time in milliseconds, or

val unixTime = System.currentTimeMillis() / 1000

for the unix time in seconds (rounded down).

Upvotes: 12

Related Questions