Skip to content

Instantly share code, notes, and snippets.

@romansavrulin
Forked from kdabir/iso_date.groovy
Created April 7, 2021 13:23
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 romansavrulin/20f88ee1938bf969085eb85a7120c966 to your computer and use it in GitHub Desktop.
Save romansavrulin/20f88ee1938bf969085eb85a7120c966 to your computer and use it in GitHub Desktop.
current date in iso 8601 in groovy
new Date().format("yyyy-MM-dd'T'HH:mm:ss'Z'", TimeZone.getTimeZone("UTC"))
Date.parse("yyyy-MM-dd'T'HH:mm:ss'Z'", dateString)
// Important: the quotes around Z help parse Z as literal in input string (represents UTC).
// If we omit quotes in format string, the numeric (ex: +0000) timezone must be present in the input string
Date.parse("yyyy-MM-dd'T'HH:mm:ss'Z'", "2001-01-01T00:00:00Z")
Date.parse("yyyy-MM-dd'T'HH:mm:ssZ", "2001-01-01T00:00:00+0000")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment