Java ZonedDateTime to toDate(@Nullable ZonedDateTime dt)

Here you can find the source of toDate(@Nullable ZonedDateTime dt)

Description

Convert the given ZonedDateTime to a Date

License

Open Source License

Parameter

Parameter Description
dt the ZonedDateTime

Return

a Date object that represents the same instant as the ZonedDateTime, at the ZonedDateTime's timezone.

Declaration

@Nullable
public static Date toDate(@Nullable ZonedDateTime dt) 

Method Source Code

//package com.java2s;
/*//from  w  w w .j  a v a  2s .  c o  m
 * 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;

public class Main {
    /**
     * Convert the given ZonedDateTime to a Date
     *
     * @param dt the ZonedDateTime
     *
     * @return a Date object that represents the same instant as the ZonedDateTime, at the ZonedDateTime's timezone.
     */
    @Nullable
    public static Date toDate(@Nullable ZonedDateTime dt) {
        if (dt == null)
            return null;
        return new Date(dt.toInstant().toEpochMilli());
    }
}

Related

  1. toDate(Optional date)