Skip to content

Instantly share code, notes, and snippets.

@kianting
Last active September 24, 2020 02:29
Show Gist options
  • Save kianting/832958a38e28d3791521d079acdf2887 to your computer and use it in GitHub Desktop.
Save kianting/832958a38e28d3791521d079acdf2887 to your computer and use it in GitHub Desktop.
import java.time.*
import java.time.format.*
def formatTime(unixEpochTime, sFormat, sTimeZone){
def objLocalDateTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(unixEpochTime), ZoneId.of(sTimeZone));
return objLocalDateTime.format(DateTimeFormatter.ofPattern("yyyy:MM:dd"));
}
​println formatTime(Math.round((new Date()).getTime()​/1000​)​, 'yyyy:MM:dd', "Pacific/Auckland")​
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment