Last active
March 18, 2022 04:53
-
-
Save TJC/2504b2d7d8be1065eae80486382469f0 to your computer and use it in GitHub Desktop.
Revisions
-
TJC revised this gist
Mar 18, 2022 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -17,10 +17,10 @@ val mysqlFormatter = new DateTimeFormatterBuilder().appendValue(YEAR, 4) .appendValue(MINUTE_OF_HOUR, 2) .optionalStart.appendLiteral(':') .appendValue(SECOND_OF_MINUTE, 2) .optionalStart.appendFraction(NANO_OF_SECOND, 1, 6, true) .toFormatter() val s = "2022-03-18 13:56:01.857" val x = LocalDateTime.parse(s, mysqlFormatter) println(x) println(f.format(x)) -
TJC renamed this gist
Mar 18, 2022 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
TJC created this gist
Mar 18, 2022 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ import java.time._ import java.time.format.{DateTimeFormatter, DateTimeFormatterBuilder} import java.time.temporal.ChronoField._ // This one doesn't work, because Mysql can return five-digits of precision, if the sixth digit was 0 val badFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS") val mysqlFormatter = new DateTimeFormatterBuilder().appendValue(YEAR, 4) .appendLiteral('-') .appendValue(MONTH_OF_YEAR, 2) .appendLiteral('-') .appendValue(DAY_OF_MONTH, 2) .appendLiteral(' ') .appendValue(HOUR_OF_DAY, 2) .appendLiteral(':') .appendValue(MINUTE_OF_HOUR, 2) .optionalStart.appendLiteral(':') .appendValue(SECOND_OF_MINUTE, 2) .optionalStart.appendFraction(NANO_OF_SECOND, 5, 6, true) .toFormatter() val s = "2022-03-18 13:56:01.85734" val x = LocalDateTime.parse(s, mysqlFormatter) println(x) println(f.format(x))