Java examples for java.time:LocalDate
Date to LocalDate
//package com.java2s; import java.time.*; import java.util.Date; public class Main { /**/*from w ww .ja v a 2s .c om*/ * Calls {@link #asLocalDate(Date, ZoneId)} with the system default time zone. */ public static LocalDate asLocalDate(Date date) { return asLocalDate(date, ZoneId.systemDefault()); } /** * Creates {@link LocalDate} from {@code java.util.Date} or it's subclasses. Null-safe. */ public static LocalDate asLocalDate(Date date, ZoneId zone) { if (date == null) return null; if (date instanceof java.sql.Date) return ((java.sql.Date) date).toLocalDate(); else return Instant.ofEpochMilli(date.getTime()).atZone(zone) .toLocalDate(); } }