ChineseDate
Introduction
ChineseDate provides methods for Chinese lunar calendar date including zodiac signs, Heavenly Stems and Earthly Branches, and traditional holidays.
Usage
- Building a ChineseDate object
ChineseDate represents a date in the Chinese lunar calendar. It can be constructed using both Gregorian and Chinese dates.
// Using Chinese date to construct
ChineseDate chineseDate = new ChineseDate(1992, 12, 14);
// Using Gregorian date to construct
ChineseDate chineseDate = new ChineseDate(DateUtil.parseDate("1993-01-06"));
- Basic usage
// Construct using Gregorian date
ChineseDate date = new ChineseDate(DateUtil.parseDate("2020-01-25"));
// Month: January (一年)
date.getChineseMonth();
// Month name:正月 (一月)
date.getChineseMonthName();
// Day: 1st day (初一)
date.getChineseDay();
// Cyclical: Gengzi (庚子)
date.getCyclical();
// Zodiac sign: Rat (生肖:鼠)
date.getChineseZodiac();
// Traditional festivals (some supported, separated by commas): Spring Festival (传统节日(部分支持,逗号分隔):春节)
date.getFestivals();
// Gengzi the Rat Year, first month, first day
date.toString();
- Getting Heavenly Stems and Earthly Branches
Starting from version 5.4.1, Hutool supports obtaining Heavenly Stems and Earthly Branches:
// Construct using Gregorian date
ChineseDate chineseDate = new ChineseDate(DateUtil.parseDate("2020-08-28"));
// Gengzi year, A Shen month, Kui Rabbit day
String cyclicalYMD = chineseDate.getCyclicalYMD();