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!
00:00
hours offset from UTC. So, Z-0700
means an offset of 07:00
hours from UTC. If you want to get this date-time at UTC, you can do so by adding 07:00
hours to 2022-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.