这个常数有用吗?在维基百科中,它写的是农历.但是这种日历没有实施.
是否存在第14个月的任何解决方案(Duodecimber)?
我在网上找不到这么多,我想更多地了解这个话题.
解决方法
虽然没有实现13个月的日历扩展java.util.Calendar,但在Java 8的新API中有一些.随着new java.time API的推出,它还创建了ThreeTen Extra project,其中包含an implementation for that.
该类是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个月之后发生了变化.
对于Ethiopian calendar,ThreeTen Extra项目也有an implementation,也有13个月.
而且,作为一个14个月的日历的例子,有PaxChronology
class,它实现了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个月,这取决于它是否是闰年.