Created
June 30, 2016 12:19
-
-
Save cardil/6d6bffd6813a06f57c3eed82ce94bb3b to your computer and use it in GitHub Desktop.
Changing Date from timestame to human readable Date from String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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