Java ZonedDateTime Calculate asZonedDateTime(Date date)

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

Description

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

License

Apache License

Declaration

public static ZonedDateTime asZonedDateTime(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  . jav a 2 s  .co m
     * Calls {@link #asZonedDateTime(Date, ZoneId)} with the system default time zone.
     */
    public static ZonedDateTime asZonedDateTime(Date date) {
        return asZonedDateTime(date, ZoneId.systemDefault());
    }

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

    /**
     * Creates an {@link Instant} from {@code java.util.Date} or it's subclasses. Null-safe.
     */
    public static Instant asInstant(Date date) {
        if (date == null)
            return null;
        else
            return Instant.ofEpochMilli(date.getTime());
    }
}

Related

  1. addOffset(ZonedDateTime time, String offset)
  2. addRandomDeltaDays(ZonedDateTime ZDT, int minDays, int maxDays, int minHour, int maxHour)
  3. addRandomDeltaMinutes(ZonedDateTime ZDT, int minMinutes, int maxMinutes)
  4. calculateTimeForSunrise(ZonedDateTime from, ZonedDateTime to)
  5. canonicalTimeString(ZonedDateTime time)
  6. cloneZonedDateTime(ZonedDateTime zonedDateTime)
  7. computeDays(ZonedDateTime Start, ZonedDateTime End)