与 Joda Time DateTime#centuryOfEra() 混淆
Confusion with Joda Time DateTime#centuryOfEra()
我正在使用 JodaTime 库 DateTime class 中的以下方法,并希望它 return 值 21。
DateTime#centuryOfEra()
return它的值为 20,这让我很困惑。谁能解释一下这背后的逻辑?
根据官方的说法documentation, the minimum value of the field centuryOfEra is 1, but when joda-time use ISOChronology那么最小值为0。
默认情况下,joda-time 使用 ISOChronology,因此 centuryOfEra 字段为 "zero based"。
这取决于您使用的年表。
有了Gregorian/Julian chronology,你就真的进入了21世纪
但是 ISOChronology 从 0 开始。
With the exception of century related fields, ISOChronology is exactly the same as GregorianChronology. In this chronology, centuries and year of century are zero based. For all years, the century is determined by dropping the last two digits of the year, ignoring sign. The year of century is the value of the last two year digits.
我正在使用 JodaTime 库 DateTime class 中的以下方法,并希望它 return 值 21。
DateTime#centuryOfEra()
return它的值为 20,这让我很困惑。谁能解释一下这背后的逻辑?
根据官方的说法documentation, the minimum value of the field centuryOfEra is 1, but when joda-time use ISOChronology那么最小值为0。
默认情况下,joda-time 使用 ISOChronology,因此 centuryOfEra 字段为 "zero based"。
这取决于您使用的年表。
有了Gregorian/Julian chronology,你就真的进入了21世纪
但是 ISOChronology 从 0 开始。
With the exception of century related fields, ISOChronology is exactly the same as GregorianChronology. In this chronology, centuries and year of century are zero based. For all years, the century is determined by dropping the last two digits of the year, ignoring sign. The year of century is the value of the last two year digits.