Here you can find the source of toZonedDateTime(@Nullable Date date, @Nullable TimeZone zone)
Parameter | Description |
---|---|
date | the Date |
zone | the TimeZone to convert to |
@Nullable public static ZonedDateTime toZonedDateTime(@Nullable Date date, @Nullable TimeZone zone)
//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()); } }