Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
You can’t perform that action at this time.