I see below datetimestamp in json but not sure which format is this??
20220914171900Z-0700
any suggestions??
Thanks in advance!
I used constructDateString but no luck!
>Solution :
- 2022 – yyyy (Year)
- 09 – MM (Month)
- 14 – dd (day of month)
- 17 – HH (Hour of day)
- 19 – mm (Minute of hour)
- 00 – ss (Second of minute)
- Z-0700 – Z stands for Zulu and represents
00:00hours offset from UTC. So,Z-0700means an offset of07:00hours from UTC. If you want to get this date-time at UTC, you can do so by adding07:00hours to2022-09-14T17:19.
Demo using Java:
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
class Main {
public static void main(String[] args) {
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("uuuuMMddHHmmss'Z'Z");
String strDateTime = "20220914171900Z-0700";
OffsetDateTime odt = OffsetDateTime.parse(strDateTime, dtf);
System.out.println(odt);
// The same date-time at UTC
OffsetDateTime odtUTC = odt.withOffsetSameInstant(ZoneOffset.UTC);
System.out.println(odtUTC);
}
}
Output:
2022-09-14T17:19-07:00
2022-09-15T00:19Z
Note: You can use y instead of u here but I prefer u to y.
Learn more about the modern Date-Time API from Trail: Date Time.