我有一個日期存儲在數據庫中,字符串格式爲ddMMyyyy,hh:mm和TimeZone。 我想根據這些信息創建一個Instant,但我不知道該怎麼做。Java 8 - 使用TimeZone從LocalDateTime創建即時
像
LocalDateTime dateTime = LocalDateTime.of(2017, Month.JUNE, 1, 13, 39);
Instant instant = dateTime.toInstant(TimeZone.getTimeZone("ECT"));
你的意思是'ZonedDateTime.ofInstant(instant,TimeZone.getDefault())'? – soorapadman
@soorapadman這將返回一個ZonedDateTime。 OP想要一個即時。 –
**不要在時區中使用3-4字符縮寫**這些*不是*實時區域,不是標準化的,甚至不是唯一的!使用[歐洲/倫敦](https://en.m。)格式的[大陸/地區]格式的[真實時區名稱](https://en.m.wikipedia.org/wiki/List_of_tz_database_time_zones) ,「歐洲/巴黎」(https://en.m.wikipedia.org/wiki/Europe/Paris),「亞洲/加爾各答」,「太平洋/奧克蘭」。如果通過「ECT」表示厄瓜多爾時間,則使用'ZoneId.of(「America/Guayaquil」)'。如果您的意思是中歐,請使用適當的歐洲/ ...區域名稱。 –