datetime - 格式化 ZonedDateTime.now()
问题描述
DateTimeFormatter.ofPattern("MM/dd/yy HH:mmaa").format(ZonedDateTime.now())
抱怨它需要一个 TemporalAccesor,而不是 ZonedDateTime。我是 DateTime 反向移植。ZonedDateTime 实现时间。Temporal 扩展了 TemporalAccessor。我预计“20 年 3 月 2 日下午 2 点 19 分”。
解决方案
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
.
推荐阅读
- r - 检测具有缺失值的前几行的变化 - 加速循环 - R
- arrays - 为什么 VBA 会提前退出我的 for 循环,为什么单元格值没有正确存储在我的数组中?
- python - 无法使用 gnupg 导入 pgp 密钥
- charts - Highcharts 使用 CSV 文件中的数据显示区域范围和折线图
- python - 具有多个 args 和 kwargs 的函数的 Multiprocessing.pool
- javascript - 如何在其他输入标签onkeyup和onchange上输入值并计算货币的汇率
- javascript - Material-UI AppBar 按钮在较小的屏幕上相互折叠
- javascript - 如何将 JS 变量传递给第二个脚本,而不能从控制台访问或改变它?
- react-apollo - 将 apollo useQuery 钩子与汇总捆绑在一起
- javascript - ReactJS 中渲染的性能问题