to LocalDate - Java java.time

Java examples for java.time:LocalDate

Description

to LocalDate

Demo Code


//package com.java2s;
import java.time.LocalDate;

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;

public class Main {
    public static LocalDate toLocalDate(Date utilDate) {
        if (utilDate == null) {
            return null;
        }//from  ww w .j  av a2  s. c  o  m
        ZonedDateTime zonedDateTime = toZonedDateTime(utilDate);
        return zonedDateTime.toLocalDate();
    }

    public static ZonedDateTime toZonedDateTime(Date utilDate) {
        if (utilDate == null) {
            return null;
        }
        final ZoneId systemDefault = ZoneId.systemDefault();
        return ZonedDateTime.ofInstant(utilDate.toInstant(), systemDefault);
    }
}

Related Tutorials