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

Java examples for java.time:LocalDateTime

Description

Convert LocalDateTime to java.util.Date

Demo Code


import java.time.DayOfWeek;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import static pl.tomaszdziurko.jvm_bloggers.utils.NowProvider.DEFAULT_ZONE;

public class Main{
    public static Date toDate(LocalDateTime localDateTime) {
        return Date.from(localDateTime.atZone(DEFAULT_ZONE).toInstant());
    }/*  ww w. j a v a 2  s.  c  om*/
}

Related Tutorials