java字符串时区转时间格式_如何在java.time中的模式字符串中格式化日期与时区?...

我有一个格式化程序的字符串模式

yyyy-MM-dd HH:mm:ss Z

如何使用这种模式解析java.util.Date?

问题是此模式中的时区已经存在.

String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss Z";

DateTimeFormatter.ofPattern(DATE_TIME_FORMAT).format(date.toInstant());

这显然给了

java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: YearOfEra

at java.time.Instant.getLong(Instant.java:603)

at java.time.format.DateTimePrintContext.getValue(DateTimePrintContext.java:298)

此处和其他地方的解决方案在格式字符串中没有时区,并提供以下解决方案:

DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.ofInstant(dateD.toInstant(), ZoneId.systemDefault()))

我可以以某种方式解析它吗?

你可能感兴趣的:(java字符串时区转时间格式)