java.util.Date to LocalDateTime - Java java.time

Java examples for java.time:LocalDateTime

Description

java.util.Date to LocalDateTime

Demo Code


//package com.java2s;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

public class Main {
    public static LocalDateTime toLocalDateTime(Date date) {
        if (date == null) {
            return null;
        }//from  ww w.j  a v  a 2  s. c  o  m
        Instant instant = Instant.ofEpochMilli(date.getTime());
        return LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
    }
}

Related Tutorials