Skip to content

Instantly share code, notes, and snippets.

@kdabir
Last active January 20, 2023 19:15
Show Gist options
  • Save kdabir/6bfe265d2f3c2f9b438b to your computer and use it in GitHub Desktop.
Save kdabir/6bfe265d2f3c2f9b438b 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")
@dsvyrjm
Copy link

dsvyrjm commented Aug 11, 2021

Any googlers in chat?

Date.parse("yyyy-MM-dd'T'HH:mm:ssXXX", "2001-01-01T00:00:00+03:00")

@ppazos
Copy link

ppazos commented Nov 12, 2021

Note this is the full expression of a datetime, but ISO8601 supports partial dates, times, datetimes and durations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment