Last active
January 20, 2023 19:15
-
-
Save kdabir/6bfe265d2f3c2f9b438b to your computer and use it in GitHub Desktop.
current date in iso 8601 in groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new Date().format("yyyy-MM-dd'T'HH:mm:ss'Z'", TimeZone.getTimeZone("UTC")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
Any googlers in chat?
Date.parse("yyyy-MM-dd'T'HH:mm:ssXXX", "2001-01-01T00:00:00+03:00")
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
Nice suggestion @reinsch82