aardio 文档

aardio 范例: 农历

import console;
import time.lunar;

//获取当前农历
var lunar = time.lunar();
console.log("2025-01-29 农历:", tostring(lunar) );

//获取指定日期农历  
var lunar = time.lunar("2025-01-09");

console.log("农历年份:", lunar.yearName + "年");
console.log("生肖:", lunar.zodiac);
console.log("农历月份:", lunar.monthFullName);
console.log("农历日期:", lunar.dayName);
console.log("农历时辰:", lunar.hourName);
console.log("完整农历:", tostring(lunar) );

//支持 time 对象的所有格式化语法,额外支持%L前缀的农历格式码
var str = tostring(lunar,"%Ly年(生肖:%LY)%Lm%Ld %LH时")

//默认输出: 甲辰年腊月初十,可选用 format 属性指定默认格式串
str = tostring(lunar) ;

//输出: 2025 年农历腊月初十
str = tostring(lunar,"%Y 年农历%Lm%Ld");
console.log(str);

//输出: 腊月初十
str = tostring(lunar,"%Lm%Ld");
console.log(str); 

//输出(农历,数值格式): 2024-12-10
console.log(lunar.format("%Lyyyy-%Lmm-%Ldd") );

//输出(公历,数值格式): 2025-01-09
console.log(lunar.format("%Y-%m-%d") );
console.more();

// 2024年农历正月初一转公历
var tm, err = time.lunar.toSolar(2024, 1, 1);
if(tm){
    console.log("2024年正月初一:", tm.format("%Y-%m-%d")); // 2024-02-10
}

// 2023年闰二月十五转公历
var tm2, err = time.lunar.toSolar(2023, 2, 15, true);
if(tm2){
    console.log("2023年闰二月十五:", tm2.format("%Y-%m-%d")); // 2023-04-05
}

// 2024年腊月三十(除夕)
var tm3 = time.lunar.toSolar(2025, 12, 29); // 2025年农历没有腊月三十
if(tm3){
    console.log("2025年 除夕:", tm3.format("%Y-%m-%d"));
}

// 错误处理:指定闰月但该年没有闰月
var tm4, err = time.lunar.toSolar(2024, 5, 1, true);
if(!tm4){
    console.fail(err); // "该年没有闰月" 或 "该年的闰月是X月,不是5月"
}
console.more();

Markdown 格式