PHPackages                             scort/lunar - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. scort/lunar

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

scort/lunar
===========

中国农历与公历互转，支持范围（1891 ~ 2100）共计210年内的农历与公历互转

V1.0.1(1y ago)113MITPHPPHP &gt;=7.4

Since Jul 20Pushed 1y ago1 watchersCompare

[ Source](https://github.com/469306621/scort-lunar)[ Packagist](https://packagist.org/packages/scort/lunar)[ RSS](/packages/scort-lunar/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)DependenciesVersions (3)Used By (0)

中国农历组件
======

[](#中国农历组件)

[Chinese Lunar Calendar Component](README.en.md)
------------------------------------------------

[](#chinese-lunar-calendar-component)

#### [中文版 ReadMe](README.md) | [English ReadMe](README.en.md)

[](#中文版-readme--english-readme)

本组件提供了中国（1891年 - 2100年）的公历与农历互转功能：

- [公历转农历，公历范围(1891-02-09 ~ 2100-12-31)](#1-%E5%85%AC%E5%8E%86%E8%BD%AC%E5%86%9C%E5%8E%86%E5%85%AC%E5%8E%86%E8%8C%83%E5%9B%B41891-02-09--2100-12-31)
- [农历转公历，农历范围(1891-1-1 ~ 2100-12-29)](#2-%E5%86%9C%E5%8E%86%E8%BD%AC%E5%85%AC%E5%8E%86%E5%86%9C%E5%8E%86%E8%8C%83%E5%9B%B41891-1-1--2100-12-29)
- [获取指定农历年的闰月](#3-%E8%8E%B7%E5%8F%96%E6%8C%87%E5%AE%9A%E5%86%9C%E5%8E%86%E5%B9%B4%E7%9A%84%E9%97%B0%E6%9C%88%E7%BB%93%E6%9E%9C0%E4%BB%A3%E8%A1%A8%E6%8C%87%E5%AE%9A%E5%B9%B4%E6%B2%A1%E6%9C%89%E9%97%B0%E6%9C%88112%E4%BB%A3%E8%A1%A8%E5%85%B7%E4%BD%93%E7%9A%84%E9%97%B0%E6%9C%88%E6%95%B0)
- [公历年闰年判断](#4-%E5%85%AC%E5%8E%86%E5%B9%B4%E9%97%B0%E5%B9%B4%E5%88%A4%E6%96%AD)
- [获取农历年生肖](#5-%E8%8E%B7%E5%8F%96%E5%86%9C%E5%8E%86%E5%B9%B4%E7%94%9F%E8%82%96)
- 其它功能陆续集成中

### 安装

[](#安装)

在项目根目录下，使用`composer`安装本组件：

```
composer require scort/lunar

```

### 在你的项目中使用

[](#在你的项目中使用)

```
// 引入
use Scort\Lunar\Lunar;

// 农历转换类
$lunar = new Lunar();
```

### 1. 公历转农历，`公历范围(1891-02-09 ~ 2100-12-31)`

[](#1-公历转农历公历范围1891-02-09--2100-12-31)

```
/**
 * 公历转农历，公历范围(1891-02-09 ~ 2100-12-31)
 */

// 指定日期
$date = date("Y-m-d");
$date = explode("-", $date);

// 转换
$todayLunar = $lunar->solarToLunar(...$date);
var_dump($todayLunar);
```

结果：

```
array(2) {
  ["status"]=> int(200)
  ["data"]=> array(8) {
    [0]=> int(2024)
    [1]=> string(6) "六月"
    [2]=> string(6) "十五"
    [3]=> string(6) "甲辰"
    [4]=> int(6)
    [5]=> int(15)
    [6]=> string(3) "龙"
    [7]=> int(0)
  }
}

 当status是200时，就有data结果，索引结果解释如下：
 * status: 200
 * data:
 *  [0] 农历年
 *  [1] 农历月
 *  [2] 农历日
 *  [3] 天干地支
 *  [4] 农历月的数字
 *  [5] 农历日的数字
 *  [6] 生肖年
 *  [7] 闰几月

 当status非200时，没有data，只有msg来描述错误信息
 * status: 非200
 * msg: 错误原因

```

### 2. 农历转公历，`农历范围(1891-1-1 ~ 2100-12-29)`

[](#2-农历转公历农历范围1891-1-1--2100-12-29)

```
/**
 * 将农历转换为公历，农历范围(1891-1-1 ~ 2100-12-29)
 *
 * @param $year :农历-年
 * @param $month :农历-月，闰月处理：例如如果当年闰五月，那么第二个五月就传六月，相当于农历有13个月
 * @param $date :农历-日
 */
$lunarYear = 1891;
$lunarMonth = 1;
$lunarDay = 1;
if ($todayLunar['status'] === 200) [$lunarYear, , , , $lunarMonth, $lunarDay] = $todayLunar['data'];
var_dump($lunar->lunarToSolar($todayLunar[0], $todayLunar[4], $todayLunar[5]));
```

结果：

```
array(2) {
  ["status"]=> int(200)
  ["date"]=> array(3) {
    [0]=> string(4) "2024"
    [1]=> string(2) "07"
    [2]=> string(2) "20"
  }
}

 当status是200时，就有data结果，索引结果解释如下：
 * status: 200
 * data:
 *  [0] 公历年
 *  [1] 公历月
 *  [2] 公历日

 当status非200时，没有data，只有msg来描述错误信息
 * status: 非200
 * msg: 错误原因

```

### 3. 获取指定农历年的闰月，结果：`0`：代表指定年没有闰月；`1~12`：代表具体的闰月数

[](#3-获取指定农历年的闰月结果0代表指定年没有闰月112代表具体的闰月数)

```
// 获取2024年的闰月
$leapMonth_2024 = $lunar->getLeapMonth(2024);
// 获取2025年的闰月
$leapMonth_2025 = $lunar->getLeapMonth(2025);
var_dump(
    $leapMonth_2024, // int 0
    $leapMonth_2025  // int 6
);
```

### 4. 公历年闰年判断

[](#4-公历年闰年判断)

```
$isLeapYear_2024 = $lunar->isLeapYear(2024);
$isLeapYear_2025 = $lunar->isLeapYear(2025);
var_dump(
    $isLeapYear_2024, // bool true
    $isLeapYear_2025  // bool false
);
```

### 5. 获取农历年生肖

[](#5-获取农历年生肖)

```
$lunarYearZodiacName = $lunar->getLunarYearZodiacName(2024);
var_dump(
    $lunarYearZodiacName // string  "龙"
);
```

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

2

Last Release

712d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5427984?v=4)[469306621](/maintainers/469306621)[@469306621](https://github.com/469306621)

---

Top Contributors

[![FengScort](https://avatars.githubusercontent.com/u/259235353?v=4)](https://github.com/FengScort "FengScort (9 commits)")

### Embed Badge

![Health badge](/badges/scort-lunar/health.svg)

```
[![Health](https://phpackages.com/badges/scort-lunar/health.svg)](https://phpackages.com/packages/scort-lunar)
```

###  Alternatives

[nuvotifier/votifier2-php

A Votifier protocol 2 implementation for PHP

146.5k](/packages/nuvotifier-votifier2-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
