jsondatedatetimetimestamptimestamp-with-timezone

What is this datetimestamp 20220914171900Z-0700 in JSON?


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

  • 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
    

    ONLINE DEMO

    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.