aardio 文档

time.lunar 库模块帮助文档

必读

农历格式化语法

time.lunar 对象兼容 time 对象的格式化语法。 并格外支持 %L 前缀的农历格式化语法,示例:

tostring(time.lunar(),"%Ly年(生肖:%LY)%Lm%Ld %LH时")

格式化参数为 tostring(timeLunarObject,format,language)

省略 format 参数则使用的默认输出格式为 %Ly年%Lm%Ld。 省略 language 参数则默认为 chs

time.lunar 对象的使用 %y-%m-%d 会输出公历日期(数值格式), 而使用 %Lyyyy-%Lmm-%Ldd 会输出农历日期(数值格式)。 格式串 %Ly年%Lm%Ld 则会输出中文农历日期。

可选使用 time.lunar 对象的 format 属性自定义默认的输出格式串。 format 也可以作为 timeLunarObject.format(format,language) 格式(ownerCall 格式)的方法调用,所有参数可选。

关于农历节气

aardio 标准库 time.lunar 提供农历月历(阴历)相关接口, 而标准库 time.sun 则提供农历二十四节气(太阳历)接口。

获取农历节气请使用 time.sun.getSolarTerm(year, nameOrLongitude) 函数。

农历(阴阳合历) ├── 阴历部分(月亮历) │ ├── 朔望月:根据月相确定月份(初一=朔日) │ ├── 大小月:大月30天,小月29天 │ └── 闰月:协调阴历年与回归年的差异 │ └── 阳历部分(太阳历) ├── 二十四节气:根据太阳黄经位置确定 ├── 节气定月:以中气定月份归属 └── 指导农事:反映季节变化

使用范例

time 成员列表 #

time.lunar() #

返回对象:TimeLunarObject

time.lunar(dateTime,...) #

解析指定公历时间并返回对应的农历时间对象。

此函数失败返回 null。

time.lunar(year,month,day,isLeap) #

直接指定农历日期并返回农历时间对象。

time.lunar 成员列表 #

农历月历支持库。
相关库 time.sun (农历节气,太阳历)。
time.julianDay (儒略日)

创建农历时间对象。
返回对象可作为 tostring 函数的参数转为农历日期完整格式,
传入 tonumber 可转为 Unix 时间戳(单位秒)。

Windows7(.NET 2.0) 开始自带此组件

time.lunar.is() #

检测参数 @1 是否 time.lunar 对象。

time.lunar.toSolar #

将农历日期转换为公历日期。

time.lunar.toSolar() #

返回对象:timeObject

time.lunar.toSolar(dateString) #

参数 @dateString 可指定 2026-01-30 格式的短日期字符串(农历日期)。
短日期之后也可以指定 %H:%M:%S,%H:%M,%H 格式的时间部分(可自右向左省略秒、分、小时)。

time.lunar.toSolar(dateTime) #

参数可指定任何包含 year,month,day 字段的表对象。
忽略参数 @dateTime 存储的实际时间并提取 year,month,day 字段作为参数(视为农历日期)

time.lunar.toSolar(year,month,day,isLeap) #

成功返回 time 对象,失败返回 null 及错误信息。

TimeLunarObject 成员列表 #

TimeLunarObject.addDays() #

添加参数 @1 指定的天数(可为正值或负值)。
此函数不会修改当前对象,而是返回新的 time.lunar 对象。

返回对象:TimeLunarObject

TimeLunarObject.addMonths() #

添加参数 @1 指定的月份数(可为正值或负值)。
此函数不会修改当前对象,而是返回新的 time.lunar 对象。

返回对象:TimeLunarObject

TimeLunarObject.addYears() #

添加参数 @1 指定的年份数(可为正值或负值)。
此函数不会修改当前对象,而是返回新的 time.lunar 对象。

返回对象:TimeLunarObject

TimeLunarObject.dateTime #

System.DateTime 对象

TimeLunarObject.day #

农历日

TimeLunarObject.dayName #

农历日中文名称,例如 "初一"

TimeLunarObject.diffDays(lunarOrTime) #

用当前对象指定参数 @lunarOrTime
指定的 time.lunar 对象或 time 对象。
返回相差的天数。

TimeLunarObject.format #

可选指定默认的输出格式串。
支持 time 对象的所有格式化语法,额外支持 %L 前缀的农历格式码。

可使用 tostring 将 time.lunar 对象(作为第一个参数)转换为字符串。
可选用 tostring 的第 2 个参数指定 format 参数(不改变对象的 format 属性)。
如果未指定 format 参数则此 format 属性为第 2 个参数的默认值。

如果在 time.lunar 的第 2 个构造参数里指定了时间格式串,
则该格式串仅用于解析输入的时间字符串,与这里控制输出的 format 属性无关。

format 也可以作为方法调用(ownerCall 格式,参数 1 可选指定格式串)。

TimeLunarObject.getDayOfWeek() #

返回星期(数值)。
0 表示周日,1~6 对应周一到周六。
也可以在格式化串中用 %a%A输出星期的文本格式。

TimeLunarObject.getDayOfYear() #

返当前农历时间是当前农历年的第几天

TimeLunarObject.getDaysInMonth() #

返回当前农历月份的总天数

TimeLunarObject.getDaysInYear() #

返回当前农历年份的总天数

TimeLunarObject.getMonthsInYear() #

返回当前农历年的月份总数

TimeLunarObject.hour #

小时

TimeLunarObject.hourFullName #

农历时辰完整名称,例如 "子时"

TimeLunarObject.hourName #

农历时辰名称,例如 "子"

TimeLunarObject.isLeapMonth #

是否为闰月

TimeLunarObject.isLeapMonth() #

当前农历时间所在月份是否闰月。

TimeLunarObject.isLeapYear() #

当前农历时间所在年份是否闰年

TimeLunarObject.month #

农历月

TimeLunarObject.monthFullName #

农历月完整中文名称,例如 "正月" 或 "闰五月"

TimeLunarObject.monthName #

农历月中文名称,例如 "正"

TimeLunarObject.solarDay #

公历日

TimeLunarObject.solarMonth #

公历月份

TimeLunarObject.solarYear #

公历年份

TimeLunarObject.timestamp #

原始时间戳(秒)

TimeLunarObject.toSolar() #

返回公历时间(time 对象)

返回对象:timeObject

TimeLunarObject.year #

农历年

TimeLunarObject.yearName #

干支年名称,例如 "甲辰"

TimeLunarObject.zodiac #

生肖名称,例如 "龙"

Markdown 格式