高精度農曆曆法庫 — 干支 · 生肖 · 節氣 · 節日 · 格式化 · 多語言
基於天文算法的農曆計算,支援中國、日本、韓國、越南四種農曆變體,以及簡體中文、繁體中文(臺灣/香港)、日本語、한국어、Tiếng Việt 六種語言。
Copyright (c) 2025 北京鋒通科技有限公司 (郭玉峰, 吳瓊). MIT License.
import { ChineseDate } from 'chinese-lunar-date'
const date = ChineseDate.fromGregorian(2024, 6, 21)
date.yearGanZhi // "甲辰"
date.zodiac // "龍"
date.zodiacEmoji // "🐉"
date.formatFull() // "甲辰龍年 五月初六"
CalendarConfig 配置驅動,同一套演算法適配不同紀元和時區歷史,而非四套獨立實作ChineseDate 等)為不可變值物件,底層演算法全部為純函式,兩種模式可獨立使用| chinese-lunar-date | date-chinese | lunar-javascript | |
|---|---|---|---|
| 精度 | 天文算法(VSOP87) | 天文算法 | 查表法 |
| TypeScript | 原生 TS,完整型別 | JSDoc 標註 | 社群 @types |
| API 風格 | 不可變值物件 | 函式式 + 內部類別 | 可變物件 |
| 干支 | 年月日三柱 | 僅年柱 | 年月日三柱 |
| 生肖 | 6 種語言 + Emoji | 無 | 僅中文 |
| 節氣 | 24 節氣,6 種語言 | 無 | 僅中文 |
| 節日 | 13 個,按地區篩選 | 無 | 僅中文 |
| 多曆法 | 中 / 日 / 韓 / 越 | 僅中國 | 僅中國 |
| 繁體中文 | zh-TW / zh-HK 分別適配 | 無 | 無 |
| 格式化 | 5 種內建 + 自訂模式 | 無 | 有限 |
| 體積 (gzip) | ~16 KB | ~15 KB | ~20 KB |
with() / addDays() 回傳新實例zh-CN / zh-TW / zh-HK / ja-JP / ko-KR / vi-VNnpm install chinese-lunar-date
import { ChineseDate } from 'chinese-lunar-date'
const date = ChineseDate.fromGregorian(2024, 6, 21)
const date2 = ChineseDate.fromDate(new Date(2024, 5, 21))
const today = ChineseDate.today()
const date3 = ChineseDate.fromValue({ cycle: 78, year: 34, month: 5, leap: false, day: 6 })
const date = ChineseDate.fromGregorian(2024, 6, 21)
date.cycle // 78
date.year // 34
date.month // 5
date.leap // false
date.day // 6
date.gregorianYear // 2024
date.yearGanZhi // "甲辰"
date.monthGanZhi // "庚午"
date.dayGanZhi // "甲寅"
date.zodiac // "龍"
date.zodiacEmoji // "🐉"
date.zodiacIndex // 4
const date = ChineseDate.fromGregorian(2024, 6, 21)
date.formatFull('zh-HK') // "甲辰龍年 五月初六"
date.formatGanZhi() // "甲辰年 庚午月 甲寅日"
date.formatCompact() // "78/34/5/0/6"
date.format('{Ygz}{Z}年 {Mname}{Dname}', 'zh-HK') // "甲辰龍年 五月初六"
const date = ChineseDate.fromGregorian(2024, 6, 21)
const tomorrow = date.addDays(1)
const yesterday = date.addDays(-1)
const firstDay = date.with({ day: 1 })
tomorrow.isAfter(date) // true
const date = ChineseDate.fromGregorian(2024, 6, 21)
date.toGregorian() // { year: 2024, month: 6, day: 21 }
date.toDate() // Date object
date.toJSON() // { cycle: 78, year: 34, month: 5, leap: false, day: 6 }
import { ChineseDate, JapaneseDate, KoreanDate, VietnameseDate } from 'chinese-lunar-date'
const cn = ChineseDate.fromGregorian(2024, 6, 21) // UTC+8
const jp = JapaneseDate.fromGregorian(2024, 6, 21) // UTC+9
const kr = KoreanDate.fromGregorian(2024, 6, 21) // UTC+8:30/9
const vn = VietnameseDate.fromGregorian(2024, 6, 21) // UTC+7/8
import { ChineseDate, solarTermName } from 'chinese-lunar-date'
ChineseDate.solarTerm(5, 2024) // 清明
solarTermName(3, 'zh-HK') // "驚蟄"
const date = ChineseDate.fromGregorian(2024, 4, 4)
date.getSolarTermName('zh-HK') // "清明"
import { ChineseDate } from 'chinese-lunar-date'
ChineseDate.festivalDate('spring', 2024) // 農曆新年
ChineseDate.festivalsInYear(2024, 'zh-HK')
// [{ name: "農曆新年", key: "spring", ... }, ...]
const date = ChineseDate.fromGregorian(2024, 2, 10)
date.getFestivals('zh-HK') // [{ name: "農曆新年", key: "spring", ... }]
內建節日列表
| Key | 農曆日期 | zh-HK |
|---|---|---|
spring |
正月初一 | 農曆新年 |
lantern |
正月十五 | 元宵節 |
dragon-head |
二月初二 | 龍抬頭 |
shangsi |
三月初三 | 上巳節 |
dragon-boat |
五月初五 | 端午節 |
qixi |
七月初七 | 七夕 |
ghost |
七月十五 | 中元節 |
mid-autumn |
八月十五 | 中秋節 |
double-ninth |
九月初九 | 重陽節 |
laba |
臘月初八 | 臘八節 |
little-new-year-south |
臘月廿四 | 小年 |
new-year-eve |
臘月三十 | 除夕 |
import { getLocale, availableLocales } from 'chinese-lunar-date'
const loc = getLocale('zh-HK')
loc.zodiac // ["鼠", "牛", "虎", "兔", "龍", "蛇", "馬", "羊", "猴", "雞", "狗", "豬"]
loc.solarTerms // ["立春", "雨水", "驚蟄", ...]
| Token | 輸出 | 範例 |
|---|---|---|
{Ygz} |
年干支 | 甲辰 |
{Z} |
生肖 | 龍 |
{Mname} |
月份名稱 | 五月 |
{Dname} |
日期名稱 | 廿八 |
{L} |
閏月標記 | 閏 |
{GY} |
公曆年 | 2024 |
{Wname} |
星期幾全稱 | 星期三 |
完整 Token 列表請參閱使用手冊。
如果您在使用過程中遇到問題,或有功能建議、商務合作等需求,歡迎透過電子郵件聯繫我們:
MIT License
Copyright (c) 2025 北京鋒通科技有限公司 (郭玉峰, 吳瓊)