Skip to content

Instantly share code, notes, and snippets.

@thorntonrose
Created April 21, 2018 16:37
Show Gist options
  • Save thorntonrose/f1c5428a921184774545ae1cb0bd5f07 to your computer and use it in GitHub Desktop.
Save thorntonrose/f1c5428a921184774545ae1cb0bd5f07 to your computer and use it in GitHub Desktop.
Convert long time value to Java or ISO string format
import groovy.util.*
import java.text.*
def cli = new CliBuilder(usage: "ConvertLongTime [options] <time>")
cli._(longOpt: "iso", "ISO format")
def opts = cli.parse(args)
if (!opts) { return }
if (!opts.arguments()) {
cli.usage()
return
}
def time = new Date(opts.arguments()[0] as long)
println (opts.iso ? new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SZ").format(time) : time)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment