LocalDateTime to ZonedDateTime

后端 未结 2 1006
礼貌的吻别
礼貌的吻别 2021-01-30 16:55

I have Java 8 Spring web app that will support multiple regions. I need to make calendar events for a customer location. So lets say my web and Postgres server is hosted in MS

2条回答
  •  野性不改
    2021-01-30 17:46

    TLDR:

    To convert from LocalDateTime to ZonedDateTime the following code. You can use .atZone( zoneId ), a comprehensive list of zoneIDs are found in the column TZ database name on Wikipedia.

    LocalDateTime localDateTime = LocalDateTime.parse( "2016-04-04T08:00" );
    ZoneId zoneId = ZoneId.of( "UTC" ); // Or "Asia/Kolkata" etc.
    ZonedDateTime zdt = localDateTime.atZone( zoneId );
    

提交回复
热议问题