该单元可以将1901-2050年间的农历日期与阳历日期之间做任意转换并提供了很多辅助函数,以帮助大家在做日程类应用时,进行相关处理。在Demos\Delphi\VCL下提供了一个Demo来演示这个用法,截图如下:
函数列表如下:
/// <summary> /// 将指定的农历年月日编码为一个TCnDate变量 /// </summary> /// <params> /// <param name="Y">农历年份,取值范围为1901-2050 </param> /// <param name="M">农历月份,负数代表是闰月</param> /// <param name="D">农历日数,取值范围为1-30</param> /// </params> /// <returns>返回编码后日期</returns> function CnDate(Y: Word; M, D: Shortint): TCnDate; inline; /// <summary>将指定的日期转换为农历日期</summary> /// <params> /// <param name=“ADate">阳历日期</param> /// </params> /// <returns>返回转换后的日期</returns> function ToCnDate(ADate: TDateTime): TCnDate; overload; /// <summary>将指定的日期转换为农历日期</summary> /// <params> /// <param name=“yyyy">阳历年份</param> /// <param name="mm">阳历月份</param> /// <param name="dd">阳历日</param> /// </params> /// <returns>返回转换后的日期</returns> function ToCnDate(yyyy, mm, dd: Word): TCnDate; overload; /// <summary>将指定农历日期转换为阳历日期</summary> /// <params> /// <param name="ADate">阴历日期</param> /// </params> /// <returns>返回转换后的阳历日期</returns> function ToEnDate(ADate: TCnDate): TDateTime; /// <summary>获取指定阳历日期的农历年份</summary> /// <params> /// <param name="ADate">阳历日期</param> /// </params> /// <returns>返回指定阳历日期的农历年份</returns> function CnYearOf(ADate: TDateTime): Smallint; overload; /// <summary>获取指定农历日期的年份的天干地支名称</summary> /// <params> /// <param name="ADate">阴历日期</param> /// </params> /// <returns>返回天干地支名称,如"甲午"</reutrns> function CnYearName(ADate: TCnDate): QStringW; overload; /// <summary>获取指定阳历日期对应的农历年份的天干地支名称</summary> /// <params> /// <param name="ADate">阴历日期</param> /// </params> /// <returns>返回天干地支名称,如"甲午"</reutrns> function CnYearName(ADate: TDateTime): QStringW; overload; /// <summary>获取指定阳历日期对应的月份数</summary> /// <params> /// <param name="ADate">阳历日期</param> /// </params> /// <returns>返回月份数,取值范围为1-12,-12~-1,负数代表是闰月</returns> function CnMonthOf(ADate: TDateTime): Shortint; overload; /// <summary>获取指定农历日期对应的月份名称</summary> /// <params> /// <param name="ADate">农历日期</param> /// </params> /// <returns>返回农历月份名称,如“腊月”</param> function CnMonthName(ADate: TCnDate): QStringW; overload; /// <summary>获取指定阳历日期对应农历日期对应的月份名称</summary> /// <params> /// <param name="ADate">农历日期</param> /// </params> /// <returns>返回农历月份名称,如“腊月”</param> function CnMonthName(ADate: TDateTime): QStringW; overload; /// <summary>获取指定农历年月的天数</summary> /// <params> /// <param name="Y">农历年份</param> /// <param name="M">农历月份,负数代表闰月</param> /// </params> /// <returns>返回指定农历年月的天数</returns> function CnMonthDays(Y: Word; M: Shortint): Byte; /// <summary>获取指定阳历日期的农历日</summary> /// <params> /// <param name="ADate">阳历日期</param> /// </params> /// <returns>返回指定的农历日</returns> function CnDayOf(ADate: TDateTime): Shortint; overload; /// <summary>获取指定农历日期的中文名称</summary> /// <params> /// <param name="ADate">农历日期</param> /// </params> /// <returns>返回指定日期的日的中文名称</returns> function CnDayName(ADate: TCnDate): QStringW; overload; /// <summary>获取指定阳历日期对应农历日期日的中文名称</summary> /// <params> /// <param name="ADate">阳历日期</param> /// </params> /// <returns>返回指定日期的日的中文名称</returns> function CnDayName(ADate: TDateTime): QStringW; overload; /// <summary>获取指定小时的时刻名称</summary> /// <params> /// <param name="AHour">小时数,取值范围0-23</param> /// </params> /// <returns>返回中文的小时对应的时刻名称(子、丑等)</returns> function CnHourName(AHour: Byte): QStringW; overload; /// <summary>获取指定的农历日期的属相名称</summary> /// <params> /// <param name="ADate">农历日期</param> /// </params> /// <returns>返回指定的农历年份对应的属相名称</returns> function CnAnimalOf(ADate: TCnDate): QStringW; overload; /// <summary>获取指定的阳历日期的属相名称</summary> /// <params> /// <param name="ADate">阳历日期</param> /// </params> /// <returns>返回指定的阳历年份对应的属相名称</returns> function CnAnimalOf(ADate: TDateTime): QStringW; overload; /// <summary>获取指定年份相应节气对应的阳历日期</summary> /// <params> /// <param name="AYear">农历年份</param> /// <param name="AName">节气名称</param> /// </params> /// <returns>返回对应的阳历日期</returns> function DateOfCnSolarTerm(AYear: Smallint; AName: QStringW) : TDateTime; overload; /// <summary>获取指定阳历日期对应的节气序号</summary> /// <params> /// <param name="AYear">阳历年份</param> /// <param name="AMonth">阳历月份</param> /// <param name="ADay">阳历日</param> /// </params> /// <returns>返回节气序列,如果不是任何节气,返回0</returns> function CnSolarTerm(AYear, AMonth, ADay: Word): Shortint; overload; /// <summary>获取指定农历日期对应的节气序号</summary> /// <params> /// <param name="AYear">农历年份</param> /// <param name="AMonth">农历月份</param> /// <param name="ADay">农历日</param> /// </params> /// <returns>返回节气序列,如果不是任何节气,返回0</returns> function CnSolarTerm(ADate: TCnDate): Shortint; overload; /// <summary>获取指定阳历日期对应的节气序号</summary> /// <params> /// <param name="ADate">阳历日期</param> /// </params> /// <returns>返回节气序列,如果不是任何节气,返回0</returns> function CnSolarTerm(ADate: TDateTime): Shortint; overload; /// <summary>获取指定农历日期对应的节气名称</summary> /// <params> /// <param name="ADate">农历日期</param> /// </params> /// <returns>返回节气名称,如果不属于任何节气,返回空字符串</returns> function CnSolarTermName(ADate: TCnDate): QStringW; overload; /// <summary>获取指定阳历日期对应的节气名称</summary> /// <params> /// <param name="ADate">阳历日期</param> /// </params> /// <returns>返回节气名称,如果不属于任何节气,返回空字符串</returns> function CnSolarTermName(ADate: TDateTime): QStringW; overload; /// <summary>获取指定日期在相应的农历年份中的周次</summary> /// <params> /// <param name="ADate">阳历日期</param> /// </params> /// <returns>返回周次</returns> function CnWeeksInYear(const ADate: TDate): Byte; /// <summary>增加指定的农历的年数</summary> /// <params> /// <param name="ADate">当前日期</param> /// <param name="ADelta">增量</param> /// </params> /// <returns>返回增加或减少(负增量)的年数后的农历日期</returns> function CnIncYear(ADate: TCnDate; ADelta: Integer = 1): TCnDate; /// <summary>增加指定的农历的月数</summary> /// <params> /// <param name="ADate">当前日期</param> /// <param name="ADelta">增量</param> /// </params> /// <returns>返回增加或减少(负增量)的月数后的农历日期</returns> function CnIncMonth(ADate: TCnDate; ADelta: Integer = 1): TCnDate; /// <summary>增加指定的农历的天数</summary> /// <params> /// <param name="ADate">当前日期</param> /// <param name="ADelta">增量</param> /// </params> /// <returns>返回增加或减少(负增量)的月数后的农历日期</returns> function CnIncDay(ADate: TCnDate; ADelta: Integer = 1): TCnDate;