How to convert ZonedDateTime to Date?

后端 未结 9 706
无人共我
无人共我 2020-12-04 09:19

I am trying to set a server agnostic date time in my database and I believe the best practice to do so is to set a UTC DateTime. My db server is Cassandra and the db driver

9条回答
  •  难免孤独
    2020-12-04 09:58

    For a docker application like beehuang commented you should set your timezone.

    Alternatively you can use withZoneSameLocal. For example:

    2014-07-01T00:00+02:00[GMT+02:00] is converted by

    Date.from(zonedDateTime.withZoneSameLocal(ZoneId.systemDefault()).toInstant())
    

    to Tue Jul 01 00:00:00 CEST 2014 and by

    Date.from(zonedDateTime.toInstant())
    

    to Mon Jun 30 22:00:00 UTC 2014

提交回复
热议问题