Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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??

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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: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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading