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

Java examples for java.time:LocalDateTime

Description

Converts the specified LocalDateTime object to Date.

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  www. j a v  a 2  s.c o  m*/
     * Converts the specified LocalDateTime object to Date.
     *
     * @param dateTime LocalDateTime object containing the date and time (JSR 310)
     * @return the created Date
     */
    public static Date localDateTimeToDate(final LocalDateTime dateTime) {
        final Instant instant = dateTime.atZone(ZoneId.systemDefault())
                .toInstant();
        return Date.from(instant);
    }
}

Related Tutorials