get timestamp kotlin
Kotlin doesn't have any time handling classes of its own, so you just use Java's java.time. For an ISO-8601 timestamp (which is the preferred format):
DateTimeFormatter.ISO_INSTANT.format(Instant.now())
That will return 2018-04-16T17:00:08.746Z. For your format, or if you need a different timezone, you can specify those:
DateTimeFormatter
.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS")
.withZone(ZoneOffset.UTC)
.format(Instant.now())
See the java.time.format.DateTimeFormatter JavaDoc for details on how to specify a format string.
The java.time classes are bundled with Android 26 and later, and with Java 8 and later. Most of the java.time functionality is back-ported to Java 6 & Java 7 in the ThreeTen-Backport project. Further adapted for earlier Android (<26) in ThreeTenABP. See How to use ThreeTenABP….
Update 2020/07
The development of ThreeTenABP is winding down. With Gradle plugin 4.0 and higher, you can directly use java 8 APIs without requiring a minimum API level for your app.
Are there any code examples left?
New code examples in category Kotlin
-
Kotlin 2022-03-27 07:55:32 kotlin split by uppercase
-
Kotlin 2022-03-27 07:40:17 var and val in kotlin
-
Kotlin 2022-03-20 03:10:23 kotlin Random()
-
Kotlin 2022-03-18 00:40:01 exported android manifest
-
Kotlin 2022-03-16 13:50:04 okhttp kotlin example
-
Kotlin 2022-03-16 05:25:02 coroutines kotlin android dependency
-
Kotlin 2022-03-14 18:05:24 arrayadapter spinner kotlin fragment
-
Kotlin 2022-03-07 04:30:37 spring boot kotlin
-
Kotlin 2022-03-06 06:05:06 kotlin scope functions
-
Kotlin 2022-02-28 03:15:02 handler kotlin