Calendar.UNDECIMBER 是做什么的?
What does Calendar.UNDECIMBER do?
Calendar
class中有个常量叫做:UNDECIMBER
。它描述了第 13 个月。
这个常量有什么用处吗?维基百科上写的是阴历。但是没有实现这样的日历。
第 14 个月 (Duodecimber) 是否有任何解决方案?
我在网上没有找到那么多,我想了解更多关于这个话题的信息。
Calendar.UNDECIMBER
是日历 class 中的一个附加常数,它通常不用于广泛使用的公历,但某些农历使用第 13 个月。这就是该字段的用途。
请参阅下面的 Java 文档:
https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#UNDECIMBER
关于此的维基百科文章:
https://en.wikipedia.org/wiki/Undecimber
维基中还提到了 第 14 个月 - Duodecimber。不幸的是,Java(目前)还不支持。
希望对您有所帮助!
如前所述,一些农历(和其他古代)日历有 13 个月。一个例子是 Coptic Calendar.
虽然没有实现扩展 java.util.Calendar
的 13 个月的日历,但在 Java 8 的新 API 中有一些。随着 new java.time API, it was also created the ThreeTen Extra project, which contains an implementation for that.
的引入
class 是 org.threeten.extra.chrono.CopticChronology
,扩展了原生 java.time.chrono.Chronology
。我刚刚制作了一个示例代码来在此日历中创建一个日期并循环显示它的月份:
// Coptic calendar
CopticChronology cal = CopticChronology.INSTANCE;
// range for month of year (from 1 to 13)
System.out.println("month range: " + cal.range(ChronoField.MONTH_OF_YEAR)); // 1 - 13
// getting a date in Coptic calendar and loop through the months
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("dd/MM/yyyy");
// September 11th is equivalent to 01/01 in Coptic calendar
CopticDate d = cal.date(LocalDate.of(2017, 9, 11));
for (int i = 0; i < 14; i++) {
System.out.println(fmt.format(d));
d = d.plus(1, ChronoUnit.MONTHS);
}
输出为:
month range: 1 - 13
01/01/1734
01/02/1734
01/03/1734
01/04/1734
01/05/1734
01/06/1734
01/07/1734
01/08/1734
01/09/1734
01/10/1734
01/11/1734
01/12/1734
01/13/1734
01/01/1735
请注意,年份在第 13 个月 之后发生了变化。
ThreeTen Extra项目也有an implementation for the Ethiopian calendar,也有13个月。
并且,作为 14 个月日历的示例,有 PaxChronology
class, which implements the Pax Calendar:提议的改革日历系统,但据我所知目前尚未使用。
引用维基百科:
The common year is divided into 13 months of 28 days each, whose names are the same as in the Gregorian calendar, except that a month called Columbus occurs between November and December. The first day of every week, month and year would be Sunday.
In leap years, a one-week month called Pax would be inserted after Columbus.
并且根据javadoc:
Leap years occur in every year whose last two digits are divisible by 6, are 99, or are 00 and the year is not divisible by 400.
示例:
PaxChronology paxCal = PaxChronology.INSTANCE;
System.out.println("month range: " + paxCal.range(ChronoField.MONTH_OF_YEAR));
PaxDate pd = paxCal.date(1930, 1, 1);
for (int i = 0; i < 15; i++) {
// fmt is the same DateTimeFormatter from previous example
System.out.println(fmt.format(pd));
// adjusting for first day of next month - using TemporalAdjuster because
// adding 1 ChronoUnit.MONTHS throws an exception for 14th month (not sure why)
pd = pd.plus(30, ChronoUnit.DAYS).with(TemporalAdjusters.firstDayOfMonth());
}
输出:
month range: 1 - 13/14
01/01/1930
01/02/1930
01/03/1930
01/04/1930
01/05/1930
01/06/1930
01/07/1930
01/08/1930
01/09/1930
01/10/1930
01/11/1930
01/12/1930
01/13/1930
01/14/1930
01/01/1931
您会注意到在第 14 个月 之后年份发生了变化。
范围是 1 - 13/14
,因为年份可以有 13 或 14 个月,具体取决于它是否是闰年。
Calendar
class中有个常量叫做:UNDECIMBER
。它描述了第 13 个月。
这个常量有什么用处吗?维基百科上写的是阴历。但是没有实现这样的日历。
第 14 个月 (Duodecimber) 是否有任何解决方案?
我在网上没有找到那么多,我想了解更多关于这个话题的信息。
Calendar.UNDECIMBER
是日历 class 中的一个附加常数,它通常不用于广泛使用的公历,但某些农历使用第 13 个月。这就是该字段的用途。
请参阅下面的 Java 文档:
https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#UNDECIMBER
关于此的维基百科文章:
https://en.wikipedia.org/wiki/Undecimber
维基中还提到了 第 14 个月 - Duodecimber。不幸的是,Java(目前)还不支持。
希望对您有所帮助!
如前所述,一些农历(和其他古代)日历有 13 个月。一个例子是 Coptic Calendar.
虽然没有实现扩展 java.util.Calendar
的 13 个月的日历,但在 Java 8 的新 API 中有一些。随着 new java.time API, it was also created the ThreeTen Extra project, which contains an implementation for that.
class 是 org.threeten.extra.chrono.CopticChronology
,扩展了原生 java.time.chrono.Chronology
。我刚刚制作了一个示例代码来在此日历中创建一个日期并循环显示它的月份:
// Coptic calendar
CopticChronology cal = CopticChronology.INSTANCE;
// range for month of year (from 1 to 13)
System.out.println("month range: " + cal.range(ChronoField.MONTH_OF_YEAR)); // 1 - 13
// getting a date in Coptic calendar and loop through the months
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("dd/MM/yyyy");
// September 11th is equivalent to 01/01 in Coptic calendar
CopticDate d = cal.date(LocalDate.of(2017, 9, 11));
for (int i = 0; i < 14; i++) {
System.out.println(fmt.format(d));
d = d.plus(1, ChronoUnit.MONTHS);
}
输出为:
month range: 1 - 13
01/01/1734
01/02/1734
01/03/1734
01/04/1734
01/05/1734
01/06/1734
01/07/1734
01/08/1734
01/09/1734
01/10/1734
01/11/1734
01/12/1734
01/13/1734
01/01/1735
请注意,年份在第 13 个月 之后发生了变化。
ThreeTen Extra项目也有an implementation for the Ethiopian calendar,也有13个月。
并且,作为 14 个月日历的示例,有 PaxChronology
class, which implements the Pax Calendar:提议的改革日历系统,但据我所知目前尚未使用。
引用维基百科:
The common year is divided into 13 months of 28 days each, whose names are the same as in the Gregorian calendar, except that a month called Columbus occurs between November and December. The first day of every week, month and year would be Sunday.
In leap years, a one-week month called Pax would be inserted after Columbus.
并且根据javadoc:
Leap years occur in every year whose last two digits are divisible by 6, are 99, or are 00 and the year is not divisible by 400.
示例:
PaxChronology paxCal = PaxChronology.INSTANCE;
System.out.println("month range: " + paxCal.range(ChronoField.MONTH_OF_YEAR));
PaxDate pd = paxCal.date(1930, 1, 1);
for (int i = 0; i < 15; i++) {
// fmt is the same DateTimeFormatter from previous example
System.out.println(fmt.format(pd));
// adjusting for first day of next month - using TemporalAdjuster because
// adding 1 ChronoUnit.MONTHS throws an exception for 14th month (not sure why)
pd = pd.plus(30, ChronoUnit.DAYS).with(TemporalAdjusters.firstDayOfMonth());
}
输出:
month range: 1 - 13/14
01/01/1930
01/02/1930
01/03/1930
01/04/1930
01/05/1930
01/06/1930
01/07/1930
01/08/1930
01/09/1930
01/10/1930
01/11/1930
01/12/1930
01/13/1930
01/14/1930
01/01/1931
您会注意到在第 14 个月 之后年份发生了变化。
范围是 1 - 13/14
,因为年份可以有 13 或 14 个月,具体取决于它是否是闰年。