Skip to content

Instantly share code, notes, and snippets.

@cardil
Created June 30, 2016 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cardil/6d6bffd6813a06f57c3eed82ce94bb3b to your computer and use it in GitHub Desktop.
Save cardil/6d6bffd6813a06f57c3eed82ce94bb3b to your computer and use it in GitHub Desktop.
Changing Date from timestame to human readable Date from String
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
directory = args[0] // directory
d = Paths.get(directory)
stream = Files.newDirectoryStream(d)
stream.each {
p = it as Path;
println "file -> ${p}"
p.toFile().eachLine { line ->
if ((matcher = line =~ /^.+(new\s+(?:java\.util\.)?Date\(([0-9]+)L\)).+$/)) {
wholeLine = matcher.getAt(0).getAt(0) as String
toReplace = matcher.getAt(0).getAt(1)
ts = matcher.getAt(0).getAt(2)
date = new Date(Long.parseUnsignedLong(ts as String))
formated = date.format('yyyy-MM-dd')
toBeReplaced = "FORMAT.parse(\"${formated}\")"
replacedLine = wholeLine.replace(toReplace as String, toBeReplaced as String)
println "wholeLine: ${wholeLine}"
println "replacedLine: ${replacedLine}"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment