Java中的玛雅日历

时间:2010-03-29 07:47:45

标签: java date calendar

如何在Java中使用Maya日历?

5 个答案:

答案 0 :(得分:6)

你的日历现在用完了吗? : - )

答案 1 :(得分:1)

在Java中使用其他日历/年表的最佳方法是优秀的Joda-Time库。它本身没有玛雅年表,但你可以自己实施玛雅规则并将其插入。不应该太繁琐。

答案 2 :(得分:1)

使用JodaTime。哎呀,对不起,在阅读有关java.util.Calendar的问题时只是反射; - )

网上有一些Java applets可能会对您有所帮助。

答案 3 :(得分:1)

如果您真的在寻找解决方案,Maya Calendar implementation看起来非常好。

它使用Java的GregorianCalendar实现了一个maya Tzolk'in calender。日期可以格里高利语或Tzolk'in格式检索。

以下是核心部分:

[...]
/** parses Date specified in Long Count format, e.g. "12.19.19.17.19" */
public void parseLongCountDate (String longCountDate) {
     String [] components = longCountDate.split("\\.");
     try {
          if (components.length != 5)
               throw new Exception("Expecting 5 numbers separated by dots");
          int baktuns = Integer.valueOf(components[0]);
          int katuns = Integer.valueOf(components[1]);
          int tuns = Integer.valueOf(components[2]);
          int winals = Integer.valueOf(components[3]);
          int kins = Integer.valueOf(components[4]);
          set (baktuns, katuns, tuns, winals, kins);
     } catch (Throwable e) {
          throw new IllegalArgumentException("Invalid long count date format: " 
          + e.getMessage());
     }
}

/** Set date to given long count date */
public void set (int baktuns, int katuns, int tuns, int uinals, int kins) {
     assert MayaTimeUnit.Kin.toDays (1) == 1;
     daysSinceGreatCycle =
          MayaTimeUnit.Baktun.toDays (baktuns) +
          MayaTimeUnit.Katun.toDays(katuns) +
          MayaTimeUnit.Tun.toDays(tuns) +
          MayaTimeUnit.Winal.toDays(uinals) +
          kins;
}

[...]

/** @return day name number in Tzolk'in calendar, e.g. it returns 0 (Ajaw) for the day "4 Ajaw" */
public Tzolkin toTzolkinDayName () {
     // The Tzolk'in date is counted forward from 4 Ajaw.
     return Tzolkin.DAYS[(daysSinceGreatCycle + 19) % 20]; // relative to Ajaw
}

/** @return day number in Tzolk'in calendar, e.g. it returns 4 for the day "4 Ajaw" */
public int toTzolkinDayNumber () {
     // The Tzolk'in date is counted forward from 4 Ajaw.
     return (daysSinceGreatCycle + 4) % 13;
}
[...]  

/** @return day name number in Haab calendar, e.g. it returns Yaxkin (5) for the day "14 Yaxk'in" */
public Haab toHaabDayName () {
     int d = (daysSinceGreatCycle + 349) % 365;
     return Haab.DAYS[d / 20];
}

/** @return day number in Haab calendar, e.g. it returns 14 for the day "14 Yaxk'in" */
public int toHaabDayNumber () {
     int d = (daysSinceGreatCycle + 349) % 365;
     return d % 20 - 1;
}
[...]  

/** @return Gregorian calendar representation of currently set date  */
public String toGregorianString () {
     Calendar c = toGregorianDate ();
     return format.format(c.getTime());
}

/** @return Converts currently defined date into Gregorian calendar */
public Calendar toGregorianDate () {
     Calendar c = (Calendar)greatCycleStartDate.clone();
     c.add(Calendar.DAY_OF_YEAR, daysSinceGreatCycle);
     return c;
}
[...]

无论如何:很酷的问题: - )

答案 4 :(得分:0)

LOL, 尝试将最后一个可选日期设为2012年12月21日? 但是它真的没有结束,它刚刚开始,所以你想在2012年12月21日之后再次开始计算?