Java LocalDateTime Create asLocalDateTime(Date date)

Here you can find the source of asLocalDateTime(Date date)

Description

Calls #asLocalDateTime(Date,ZoneId) with the system default time zone.

License

Apache License

Declaration

public static LocalDateTime asLocalDateTime(Date date) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.time.*;
import java.util.Date;

public class Main {
    /**/*from www . j  a  va2s.  c o  m*/
     * Calls {@link #asLocalDateTime(Date, ZoneId)} with the system default time zone.
     */
    public static LocalDateTime asLocalDateTime(Date date) {
        return asLocalDateTime(date, ZoneId.systemDefault());
    }

    /**
     * Creates {@link LocalDateTime} from {@code java.util.Date} or it's subclasses. Null-safe.
     */
    public static LocalDateTime asLocalDateTime(Date date, ZoneId zone) {
        if (date == null)
            return null;

        if (date instanceof java.sql.Timestamp)
            return ((java.sql.Timestamp) date).toLocalDateTime();
        else
            return Instant.ofEpochMilli(date.getTime()).atZone(zone).toLocalDateTime();
    }
}

Related

  1. asLocalDateTime(Date date)
  2. getLocalDateTime(Date datetime, TimeZone timeZone)
  3. getLocalDateTimeFromEpochMilli(long epochMillis)
  4. getLocalDateTimeFromMillis(final long millis)
  5. getLocalDateTimeFromMillis(long millis)