Created
August 13, 2017 06:46
-
-
Save petitviolet/db171d9c8cf023c76a02cd66452ab2cd to your computer and use it in GitHub Desktop.
JodaTime <-> LocalDateTime snippet
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 characters
| object DateTimeConverters { | |
| implicit class DateTimeConverter(val ldt: LocalDateTime) extends AnyVal { | |
| def asJoda: DateTime = { | |
| val instant = ldt.atZone(ZoneId.systemDefault()).toInstant | |
| new DateTime(instant.toEpochMilli) | |
| } | |
| } | |
| implicit class JodaConverter(val jdt: DateTime) extends AnyVal { | |
| def asLocalDateTime: LocalDateTime = { | |
| LocalDateTime.of( | |
| jdt.getYear, | |
| jdt.getMonthOfYear, | |
| jdt.getDayOfMonth, | |
| jdt.getHourOfDay, | |
| jdt.getMinuteOfHour, | |
| jdt.getSecondOfMinute, | |
| jdt.getMillisOfSecond * 1000000 | |
| ) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment