Last active
December 23, 2015 04:55
-
-
Save ankushs92/607fcd382088cb5e8379 to your computer and use it in GitHub Desktop.
Friends don't let friends use java.util.Date !
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
public class DateUtils{ | |
/* | |
* Converts java.util.Date object to a java.time.LocalDate | |
* Things are so much more convenient now! | |
*/ | |
public static LocalDate asLocalDate(final Date date){ | |
return Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.systemDefault()).toLocalDate(); | |
} | |
/* | |
* When you need a java.util.Date object just because some | |
* library that you are using uses it. | |
*/ | |
public static Date asDate(final LocalDate localDate){ | |
return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment