1

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!

IamSumanth
  • 23
  • 2
  • 1
    It must be a homegrown format from somewhere. Nothing I have seen before (and I have seen many). It’s reminding of the compact (“basic”) [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, which your JSON should probably prefer instead. It would go like `20220914T171900-0700` (`T` preceding the time part and no `Z`). – Ole V.V. Jan 11 '23 at 15:28
  • Thanks, @OleV.V. for adding this useful link here. – Arvind Kumar Avinash Jan 11 '23 at 16:05

1 Answers1

3
  • 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: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

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.

Arvind Kumar Avinash
  • 71,965
  • 6
  • 74
  • 110