首页 > 解决方案 > 格式化 ZonedDateTime.now()

问题描述

DateTimeFormatter.ofPattern("MM/dd/yy HH:mmaa").format(ZonedDateTime.now())

抱怨它需要一个 TemporalAccesor,而不是 ZonedDateTime。我是 DateTime 反向移植。ZonedDateTime 实现时间。Temporal 扩展了 TemporalAccessor。我预计“20 年 3 月 2 日下午 2 点 19 分”。

标签: datetime

解决方案


I was using a java formatter, java.time.format.DateTimeFormatter but a backport time, org.threeten.bp.ZonedDateTime. They don’t work together.

An obvious solution is to import java.time.ZonedDateTime instead.

Or if you’ve got specific reasons for using the backport, then org.threeten.bp.format.DateTimeFormatter.


推荐阅读