Created
March 10, 2015 07:33
-
-
Save zerosum/6cf764b2026811491cb0 to your computer and use it in GitHub Desktop.
LocalDateTime <-> Date
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
| import java.time.LocalDateTime; | |
| import java.time.ZoneId; | |
| import java.time.ZoneOffset; | |
| import java.util.Date; | |
| import java.util.function.Function; | |
| import java.util.function.UnaryOperator; | |
| public class DateWrapper { | |
| private LocalDateTime localDateTime; | |
| public DateWrapper(Date date) { | |
| this.localDateTime = LocalDateTime.ofInstant(date.toInstant(), ZoneOffset.systemDefault()); | |
| } | |
| public DateWrapper(LocalDateTime localDateTime) { | |
| this.localDateTime = localDateTime; | |
| } | |
| public DateWrapper map(UnaryOperator<LocalDateTime> f) { | |
| this.localDateTime = f.apply(localDateTime); | |
| return this; | |
| } | |
| public Boolean is(Function<LocalDateTime, Boolean> f) { | |
| return f.apply(localDateTime); | |
| } | |
| public LocalDateTime toLocalDateTime() { | |
| return localDateTime; | |
| } | |
| public Date toDate() { | |
| return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment