Skip to content

Instantly share code, notes, and snippets.

@nbenns
Last active October 28, 2019 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nbenns/29ee5217a3881bb1072b1008c4c88104 to your computer and use it in GitHub Desktop.
Save nbenns/29ee5217a3881bb1072b1008c4c88104 to your computer and use it in GitHub Desktop.
Using ZonedDateTime properly
def fromISOString(d: String): ZonedDateTime =
ZonedDateTime.parse(d, DateTimeFormatter.ISO_OFFSET_DATE_TIME).withZoneSameInstant(ZoneOffset.UTC)
def toISOString(d: ZonedDateTime) = d.withZoneSameInstant(ZoneOffset.UTC).format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)
// parsing a "date only"
LocalDate.parse(str).atStartOfDay(ZoneOffset.UTC)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment