Java SQL Timestamp to ZonedDateTime

女生的网名这么多〃 提交于 2020-01-06 05:26:10

问题


I want to cast a ZonedDateTime object into a java.sql.Timestamp object without using the local date.

For example, let's say I have the following datetime :

System.out.println(myZonedDateTime);
> 2018-09-02T23:55:05+04:00[Asia/Dubai]

And my local timezone is UTC+08:00

I try to parse my ZonedDateTime to a Timestamp :

Timestamp t = Timestamp.from(myZonedDateTime.toInstant());
System.out.println(t);
> 2018-09-03 04:55:05.0

The value I get in my timestamp depends of my local time, when I want it to depends of the ZoneId of my data.

How is it possible to do this ?

来源:https://stackoverflow.com/questions/52943309/java-sql-timestamp-to-zoneddatetime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!