Skip to content

Instantly share code, notes, and snippets.

@InsulaVentus
Created July 24, 2019 11:32
Show Gist options
  • Save InsulaVentus/c2626fafcd115d87a131f61e54799a19 to your computer and use it in GitHub Desktop.
Save InsulaVentus/c2626fafcd115d87a131f61e54799a19 to your computer and use it in GitHub Desktop.

Say you have a string with a date and a time, e.g "24.07.2019 12:49", but no time zone. And you want to format that string according to the ISO-8601 standard, with offset, e.g "2019-07-24T12:49:00+02:00".

In java:

LocalDate date = LocalDate.parse("27.07.2019", DateTimeFormatter.ofPattern("dd.MM.yyyy"));
LocalTime time = LocalTime.parse("12:49");
        
LocalDateTime.of(date, time)
        .atZone(ZoneId.of("Europe/Oslo"))
        .toOffsetDateTime()
        .format(DateTimeFormatter.ISO_OFFSET_DATE_TIME); //"2019-07-24T12:49:00+02:00"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment