'timestamp UTC+0 in java or kotlin
Could someone know how to generate a timestamp format like this
“timestamp” : “2022-04-30T08:40:02.640+00:00”
I don’t recognize the format and don’t know how to generate it win kotlin, and it should be UTC+0. There are so many way to generate time, datetime and timestamp…I’m confused.
Solution 1:[1]
You can use DateTimeFormatter with ISO_OFFSET_DATE_TIME for this
In Java
OffsetDateTime offsetDateTime = Instant.ofEpochMilli(timeInMillis).atOffset(ZoneOffset.ofHoursMinutes(hours, minutes));
String formatted = offsetDateTime.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
In Kotlin
val offSetDateTime = Instant.ofEpochMilli(timeInMillis).atOffset(oneOffset.ofHoursMinutes(hours, minutes))
val formatted = current.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)
Output - '2011-12-03T10:15:30+01:00'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Praveen |
