Skip to content

Instantly share code, notes, and snippets.

@ankushs92
Last active December 23, 2015 04:55
Show Gist options
  • Save ankushs92/607fcd382088cb5e8379 to your computer and use it in GitHub Desktop.
Save ankushs92/607fcd382088cb5e8379 to your computer and use it in GitHub Desktop.
Friends don't let friends use java.util.Date !
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