to LocalDateTime - Java java.time

Java examples for java.time:LocalDateTime

Description

to LocalDateTime

Demo Code


//package com.java2s;

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

public class Main {
    public static LocalDateTime toLocalDateTime(Date utilDate) {
        if (utilDate == null) {
            return null;
        }/*www. j ava 2  s.  c  o  m*/
        ZonedDateTime zonedDateTime = toZonedDateTime(utilDate);
        return zonedDateTime.toLocalDateTime();
    }

    public static ZonedDateTime toZonedDateTime(Date utilDate) {
        if (utilDate == null) {
            return null;
        }
        final ZoneId systemDefault = ZoneId.systemDefault();
        return ZonedDateTime.ofInstant(utilDate.toInstant(), systemDefault);
    }
}

Related Tutorials