【发布时间】:2019-04-11 19:25:29
【问题描述】:
我有一个 Date 对象,其中包含一个日期(不是当前日期),我需要以某种方式指定该日期为 UTC,然后将其转换为 +1 小时的“欧洲/巴黎”。
public static LocalDateTime toLocalDateTime(Date date){
return ZonedDateTime.of(LocalDateTime.ofInstant(date.toInstant(), ZoneOffset.UTC), ZoneId.of("Europe/Paris")).toLocalDateTime();
}
给定日期“2018-11-08 15:00:00”,这会将日期转换为“2018-11-08 14:00:00”。我需要它从 UTC 转换为欧洲/巴黎 - 而不是相反。
【问题讨论】:
-
既然可以直接从
Instant构造ZonedDateTime,为什么还要经过LocalDateTime?
标签: java date timezone zoneddatetime