PHPackages                             ionepub/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. ionepub/lunar

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

ionepub/lunar
=============

农历公历转换，阳历转阴历，阴历转阳历，今天的阴历日期 A Chinese calendar transform class

1.0(7y ago)127MITPHPPHP ~5.4

Since Sep 14Pushed 7y ago1 watchersCompare

[ Source](https://github.com/ionepub/lunar)[ Packagist](https://packagist.org/packages/ionepub/lunar)[ Docs](https://github.com/ionepub)[ RSS](/packages/ionepub-lunar/feed)WikiDiscussions master Synced 4w ago

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

lunar
=====

[](#lunar)

农历公历转换，阳历转阴历，阴历转阳历，今天的阴历日期。 A Chinese calendar transform class.

[![Latest Stable Version](https://camo.githubusercontent.com/1a3a25bef949658639b0747fde4db5a24ea18b745aef65d23546a038cc9788d6/68747470733a2f2f706f7365722e707567782e6f72672f696f6e657075622f6c756e61722f762f737461626c65)](https://packagist.org/packages/ionepub/lunar)

[![Total Downloads](https://camo.githubusercontent.com/761473782eebd3d773952021998dfb1ac29bbaba6401a93284b81f750bcf3c69/68747470733a2f2f706f7365722e707567782e6f72672f696f6e657075622f6c756e61722f646f776e6c6f616473)](https://packagist.org/packages/ionepub/lunar)

[![Latest Unstable Version](https://camo.githubusercontent.com/3f73957a2fa83db2d52a4b6b99ae45580844e670870aed37395ade3ce1161d63/68747470733a2f2f706f7365722e707567782e6f72672f696f6e657075622f6c756e61722f762f756e737461626c65)](https://packagist.org/packages/ionepub/lunar)

[![License](https://camo.githubusercontent.com/f420022f01fdc759c58b5aa885120717aac7efc53f2bff44b7f97e8a94de9923/68747470733a2f2f706f7365722e707567782e6f72672f696f6e657075622f6c756e61722f6c6963656e7365)](https://packagist.org/packages/ionepub/lunar)

安装
--

[](#安装)

### 使用composer安装（建议）

[](#使用composer安装建议)

```
# 稳定版本
composer require ionepub/lunar
composer require --prefer-dist ionepub/lunar

# 开发版本
composer require ionepub/lunar:dev-master -vvv

```

### 直接下载

[](#直接下载)

下载地址：

使用
--

[](#使用)

### 实例化

[](#实例化)

```
require 'vendor/autoload.php';
use Ionepub\Lunar;

$lunar = Lunar::getInstance();
```

### 设置一个阳历日期

[](#设置一个阳历日期)

```
$lunar->solar(2018, 9, 10);

# 注意，不能这样传入日期，这样的参数可能会被过滤，如果是两位的日期，应转为字符串
$lunar->solar(2018, 09, 08); // success
$lunar->solar('2018', '09', '08'); // failed
```

### 设置一个阴历日期

[](#设置一个阴历日期)

```
$lunar->lunar(2018, 8, 5);
$lunar->lunar('2018', '08', '05');

// lunar方法中第四个参数表示阴历闰月，如果当前阴历日期是闰月的，需要明确传递true
$lunar->lunar(2017, 6, 2, true);
```

### 设置日期为今天

[](#设置日期为今天)

```
$lunar->solar();
$lunar->lunar();
```

### 获取日期信息

[](#获取日期信息)

```
$result = $lunar->get();
// =>
//    Array
//    (
//	    [year] => 阳历年
//	    [month] => 阳历月
//	    [day] => 阳历日
//	    [lunar_year] => 阴历年
//	    [lunar_month] => 阴历月
//	    [lunar_day] => 阴历日
//	    [lunar_year_chinese] => （中文）阴历年
//	    [lunar_month_chinese] => （中文）阴历月
//	    [lunar_day_chinese] => （中文）阴历日
//	    [is_leap] => 是否闰月
//    )
```

支持链式操作：

```
$result = $lunar->solar()->get();
```

### 获取日期字符串

[](#获取日期字符串)

通过向`str()`方法传递第一个参数，可以指定返回的日期类型，分别有：

- Lunar::SOLAR 阳历日期，默认
- Lunar::LUNAR 阴历日期
- Lunar::LUNAR\_CN 阴历日期（中文）

```
$date_str = $lunar->str(); // 2018-09-14
$date_str = $lunar->str(Lunar::SOLAR); // 2018-09-14
$date_str = $lunar->str(Lunar::LUNAR); // 2018-08-05
$date_str = $lunar->str(Lunar::LUNAR_CN); // 二零一八-八月-初五
```

可以通过向`str()`方法传递分隔符参数来设置返回的字符串格式，默认 `-`

```
$date_str = $lunar->str(Lunar::SOLAR); // 2018-09-14
$date_str = $lunar->str(Lunar::SOLAR, ' '); // 2018 09 14
$date_str = $lunar->str(Lunar::SOLAR, '.'); // 2018.09.14
```

同样支持链式操作：

```
$date_str = $lunar->lunar()->str();
```

示例
--

[](#示例)

### \#已知用户的生日，获取下一次生日的日期

[](#已知用户的生日获取下一次生日的日期)

```
# 如果为阳历生日
$date = '1993-09-14';
$date_arr = explode("-", $date);
$date_arr[0] = date('Y');
if( date("Y-m-d") > implode("-", $date_arr) ){
    // 今年生日已过，获取下一年
    $date_arr[0]++;
}
$next = $calendar->solar($date_arr[0], $date_arr[1], $date_arr[2])->get();
print_r($next);

# 如果为阴历生日
$date = '1993-09-14';
$date_arr = explode("-", $date);
$date_arr[0] = date('Y');
if( $calendar->lunar()->str() > implode("-", $date_arr) ){
    // 今年生日已过，获取下一年
    $date_arr[0]++;
}
$next = $calendar->lunar($date_arr[0], $date_arr[1], $date_arr[2])->get();
print_r($next);
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity56

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

Unknown

Total

1

Last Release

2794d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a6f4f3c231f8411117d2a8d68e1be40e82064f9c8a618cc671da798ad1352315?d=identicon)[ionepub](/maintainers/ionepub)

---

Top Contributors

[![ionepub](https://avatars.githubusercontent.com/u/16647246?v=4)](https://github.com/ionepub "ionepub (2 commits)")

---

Tags

calendarlunarlunar2solarsolarsolar2lunarcalendarChineselunarsolarsolar2lunarlunar2solartoday

### Embed Badge

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

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

###  Alternatives

[overtrue/chinese-calendar

中国农历转换与查询工具

557103.7k4](/packages/overtrue-chinese-calendar)[eluceo/ical

The eluceo/iCal package offers an abstraction layer for creating iCalendars. You can easily create iCal files by using PHP objects instead of typing your \*.ics file by hand. The output will follow RFC 5545 as best as possible.

1.2k17.5M46](/packages/eluceo-ical)[spatie/icalendar-generator

Build calendars in the iCalendar format

6787.4M9](/packages/spatie-icalendar-generator)[6tail/lunar-php

lunar是一款无第三方依赖的日历工具，支持公历(阳历)、农历(阴历、老黄历)、佛历和道历，支持星座、儒略日、干支、生肖、节气、节日、彭祖百忌、每日宜忌、吉神宜趋、凶煞宜忌、吉神(喜神/福神/财神/阳贵神/阴贵神)方位、胎神方位、冲煞、纳音、星宿、八字、五行、十神、建除十二值星、青龙名堂等十二神、黄道日及吉凶等。lunar is a calendar library for Solar and Chinese Lunar.

19326.3k4](/packages/6tail-lunar-php)[phpu/calendar

中国日历，通过天文计算和民间推算方法，准确计算出公历-1000年至3000年的农历、干支、节气等，同时支持多配置、多语言、多时区。

201.7k](/packages/phpu-calendar)[moe/full-calendar

A lightweight calendar module for Silverstripe. Implements the popular javascript http://fullcalendar.io/ library.

121.5k](/packages/moe-full-calendar)

PHPackages © 2026

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