Here you can find the source of convertForPersistence(@Nullable ZonedDateTime dt)
Parameter | Description |
---|---|
dt | the ZonedDateTime to convert to UTC |
@Nullable public static Date convertForPersistence(@Nullable ZonedDateTime dt)
//package com.java2s; /*//from w ww . j a v a2 s . 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.ZoneOffset; import java.time.ZonedDateTime; import java.util.Date; import java.util.TimeZone; public class Main { /** UTC. */ public static final TimeZone UTC = TimeZone.getTimeZone(ZoneOffset.UTC); /** * Convert the given ZonedDateTime to a UTC date for persistence * * @param dt the ZonedDateTime to convert to UTC * * @return a Date object that represents the same instant as the ZonedDateTime, but at UTC. */ @Nullable public static Date convertForPersistence(@Nullable ZonedDateTime dt) { if (dt == null) return null; ZonedDateTime atUtc = dt.withZoneSameInstant(ZoneOffset.UTC); return new Date(atUtc.toInstant().toEpochMilli()); } }