当我为那个时代创建格式化程序时:
import java.time.*
import java.time.format.*
var formatter = DateTimeFormatter.ofPattern("G");
然后使用它,我得到n.e。而不是例如AD。
formatter.format(LocalDateTime.now()); //n.e.
为什么时代被格式化为n.e?
我在ubuntu仿生上使用Java 11:
openjdk 11 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)
您有一个旧的Java安装,并且看来efault Chronology是日语的。
formatter.getChronology()
的结果是什么?
n.e.
代表New Era
,于2019年5月1日在火影忍者天皇登基后在日本开始。该时代被称为“ Reiwa”,而新的JRE将“ G”格式设置为Reiwa
。
在我的系统上,默认年代为null
,时代格式为AD
。
如果需要AD
,请明确使用IsoEra
确保它:var formatterIso = formatter.withChronology(IsoChronology.INSTANCE);