Converts the specified Date object to LocalDateTime. - Java java.time

Java examples for java.time:LocalDateTime

Description

Converts the specified Date object 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 {
    /**/*from  ww  w .  j  a  v  a  2s  .  c  om*/
     * Converts the specified Date object to LocalDateTime.
     *
     * @param date Date object containing the date and time
     * @return the created LocalDateTime (JSR 310)
     */
    public static LocalDateTime dateToLocalDateTime(final Date date) {
        final Instant instant = Instant.ofEpochMilli(date.getTime());
        return LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
    }
}

Related Tutorials