Java ZonedDateTime Create toZonedDateTime(@Nullable Date date, @Nullable TimeZone zone)

Here you can find the source of toZonedDateTime(@Nullable Date date, @Nullable TimeZone zone)

Description

Convert the given Date to a ZonedDateTime at the given TimeZone

License

Open Source License

Parameter

Parameter Description
date the Date
zone the TimeZone to convert to

Return

a ZonedDateTime that represents the same instant as the Date, at the TimeZone specified.

Declaration

@Nullable
public static ZonedDateTime toZonedDateTime(@Nullable Date date, @Nullable TimeZone zone) 

Method Source Code

//package com.java2s;
/*//ww  w.  j a  v a 2s.c  om
 * Copyright (c) Interactive Information R & D (I2RD) LLC.
 * All Rights Reserved.
 *
 * This software is confidential and proprietary information of
 * I2RD LLC ("Confidential Information"). You shall not disclose
 * such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered
 * into with I2RD.
 */

import javax.annotation.Nullable;

import java.time.ZonedDateTime;

import java.util.Date;

import java.util.TimeZone;

public class Main {
    /**
     * Convert the given Date to a ZonedDateTime at the given TimeZone
     *
     * @param date the Date
     * @param zone the TimeZone to convert to
     *
     * @return a ZonedDateTime that represents the same instant as the Date, at the TimeZone specified.
     */
    @Nullable
    public static ZonedDateTime toZonedDateTime(@Nullable Date date, @Nullable TimeZone zone) {
        if (date == null || zone == null)
            return null;
        return ZonedDateTime.ofInstant(date.toInstant(), zone.toZoneId());
    }
}

Related

  1. toZonedDateTime(Date utilDate)
  2. toZonedDateTime(long epochSeconds)
  3. toZonedDateTime(long systemMillis)
  4. toZonedDateTime(Object cell)