Convert Date to LocalDateTime of Java 8 - Java java.time

Java examples for java.time:LocalDateTime

Description

Convert Date to LocalDateTime of Java 8

Demo Code


//package com.java2s;

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

public class Main {
    /**/*from  w  w w.  j  av a  2  s .  c o m*/
     * Convert Date to LocalDateTime of Java8
     * @param date
     * @return
     */
    public static Date toDate(LocalDateTime localDateTime) {
        if (localDateTime == null)
            return null;
        return Date.from(localDateTime.atZone(ZoneId.systemDefault())
                .toInstant());
    }
}

Related Tutorials