Skip to content

Instantly share code, notes, and snippets.

@ppazos
Forked from kdabir/iso_date.groovy
Created October 13, 2019 00:17
Show Gist options
  • Save ppazos/c1e00c3a9b720fe5906883ac9ead825c to your computer and use it in GitHub Desktop.
Save ppazos/c1e00c3a9b720fe5906883ac9ead825c 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