How to Get Date Time for Specific Timezone and Date in Specific Format

The below code for gets datetime for the New Zealand timezone. For more information on DateTime and available Timezones, please check our API.

Groovy
def todayDateTime = new DateTime()
def nzTimeZone = api.getTimeZone("NZ")
def todayText = todayDateTime.withZone(nzTimeZone).toString("yyyy-MM-dd")

Alternatively:

Groovy
def date = new Date()
def offset = api.getTimeZone("NZ").getOffset(date)
def shiftedDate = new Date(date + offset)