Skip to content

Instantly share code, notes, and snippets.

@JFFail
Created June 5, 2020 20:39
Show Gist options
  • Save JFFail/dabd6ab1334fb00bfe5e089d8072ac3c to your computer and use it in GitHub Desktop.
Save JFFail/dabd6ab1334fb00bfe5e089d8072ac3c to your computer and use it in GitHub Desktop.
Get a Date object at a specified Date and Time as an ISO formatted string in UTC
TimeZone.setDefault(TimeZone.getTimeZone('UTC'))
Integer year = Calendar.getInstance().get(Calendar.YEAR)
Integer month = Calendar.getInstance().get(Calendar.MONTH)
def then = new GregorianCalendar(year, month, 1, 0, 0, 0).time
// Desired format: 2020-06-01T00:00:00.000000+00:00
thenISO = then.format("yyyy-MM-dd'T'HH:mm:ss.SSSZ", TimeZone.getTimeZone("UTC"))
thenISOFixed = thenISO[0..thenISO.length() - 3] + ":00"
println thenISOFixed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment