The LunarCalendarConverter class is a utility class that converts a given Gregorian (Western) calendar date to its corresponding lunar (Chinese) calendar date.

The class contains the following constants:

  • 'LUNAR_MONTHS': An array of strings representing the names of the lunar months.
  • 'LUNAR_DAYS': An array of strings representing the names of the lunar days.
  • 'LUNAR_DAY_COUNTS': An array of integers representing the number of days in each lunar month.
  • 'LUNAR_DIGITS': An array of strings representing the Chinese characters for the digits 0-9.
  • 'BASE_YEAR': An integer representing the base year of the lunar calendar (1900).

The class also contains a 'main' method that gets the current Gregorian date, calculates the corresponding lunar date, and prints both dates.

The 'main' method performs the following steps:

  1. Gets the current Gregorian date using the 'LocalDate.now()' method.
  2. Extracts the year, month, and day from the Gregorian date.
  3. Checks if the year is within the supported range (1900-2100).
  4. Calculates the lunar year by subtracting the base year from the Gregorian year.
  5. Retrieves the lunar data for the lunar year.
  6. Extracts the high and low bytes from the lunar data.
  7. Retrieves the leap month and leap day from the high byte.
  8. Checks if the Gregorian year is a leap year.
  9. Calculates the number of leap months before the current month.
  10. Adjusts the current month if it is after the leap month.
  11. Calculates the lunar month by counting the set bits in the low byte.
  12. Sets the lunar day to the Gregorian day.
  13. Adds the leap day to the lunar day if the current month is the leap month.
  14. Converts the lunar day to its Chinese representation.
  15. Prints the Gregorian date and the lunar date.
农历转换器:将公历日期转换为农历日期

原文地址: https://www.cveoy.top/t/topic/fSro 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录