PHPackages                             zjkal/time-helper - 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. zjkal/time-helper

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

zjkal/time-helper
=================

一个简单快捷的PHP日期时间助手类库。 a smart PHP datetime helper library.

v1.1.17(1mo ago)21030.2k↑401.7%201MITPHPPHP &gt;=7.1CI passing

Since Aug 24Pushed 1mo ago4 watchersCompare

[ Source](https://github.com/zjkal/time-helper)[ Packagist](https://packagist.org/packages/zjkal/time-helper)[ RSS](/packages/zjkal-time-helper/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (10)Dependencies (2)Versions (31)Used By (1)

 [![TimeHelper](https://camo.githubusercontent.com/683f8a88303e8067d74ab15b428e135b6638e0a737eefd93755231862127d592/68747470733a2f2f63646e2e3078312e736974652f6c6f676f2d74696d652d68656c7065722e737667)](https://camo.githubusercontent.com/683f8a88303e8067d74ab15b428e135b6638e0a737eefd93755231862127d592/68747470733a2f2f63646e2e3078312e736974652f6c6f676f2d74696d652d68656c7065722e737667)

 中文 | [English](https://github.com/zjkal/time-helper/blob/main/README_EN.md)

 [ ![License](https://camo.githubusercontent.com/f809d00ba75dc1dc7fb07ce8d6c934a11ceb1f44571b52427e7a34be8afb97ba/68747470733a2f2f706f7365722e707567782e6f72672f7a6a6b616c2f74696d652d68656c7065722f6c6963656e7365) ](https://github.com/zjkal/time-helper/blob/main/LICENSE) [ ![PHP Version Require](https://camo.githubusercontent.com/cfbd92d3b117217454466301c51fb798fa2a21e25e35414b48ce06f91f18edc2/68747470733a2f2f706f7365722e707567782e6f72672f7a6a6b616c2f74696d652d68656c7065722f726571756972652f706870) ](https://github.com/zjkal/time-helper) [ ![Latest Stable Version](https://camo.githubusercontent.com/725b9c6a658c307461bbd703aab902e876d684693266c125ee10c7ee23f03c86/68747470733a2f2f706f7365722e707567782e6f72672f7a6a6b616c2f74696d652d68656c7065722f76) ](https://github.com/zjkal/time-helper) [ ![Total Downloads](https://camo.githubusercontent.com/94a8b029e62a7cda51ba4e7e0bc536812d8109b7be2cdcf57c946961ea774a8a/68747470733a2f2f706f7365722e707567782e6f72672f7a6a6b616c2f74696d652d68656c7065722f646f776e6c6f616473) ](https://packagist.org/packages/zjkal/time-helper) [ ![GitHub Workflow Status](https://camo.githubusercontent.com/e22c71f4268f735f406e194026a71e3835445b9e165cb564700dbed4282a213e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7a6a6b616c2f74696d652d68656c7065722f2e6769746875622f776f726b666c6f77732f636f6d706f7365722e796d6c3f6272616e63683d6d61696e) ](https://github.com/zjkal/time-helper)

`TimeHelper` 是一个简单易用的`PHP时间日期助手类库`,可以快速实现常用的时间日期操作,比如获取指定时间的秒数,获取友好的时间格式,判断时间范围,计算两个时间相差值,返回 N 小时/天/星期/月/年前或者后的时间戳等等

🧩 特性
----

[](#-特性)

- 简单易用: 不依赖任何扩展,`开箱即用`
- 化繁为简: 所有方法都可以传入`任意类型的时间日期格式`或`时间戳`
- 快捷高效: 所有操作只需要`一个静态方法`即可完成

🎁 示例
----

[](#-示例)

```
//判断指定日期是否为国内的工作日
ChinaHoliday::isWorkday('2023-01-23');

//判断指定日期是否为国内的节假日
ChinaHoliday::isHoliday(1646360133);

//返回友好的时间格式,如:刚刚,N秒前,N分钟前,N小时前等等
TimeHelper::toFriendly('2022-3-2 10:15:33');
//返回友好的时间格式(英文)
TimeHelper::toFriendly(1646186290, 'en');

//判断日期是否为今天
TimeHelper::isToday('2020-4-10 23:01:11');

//判断日期是否为工作日(周一到周五)
TimeHelper::isWeekday('2023-03-08');

//计算两个日期相差天数
TimeHelper::diffDays('2022-4-10 23:01:11','Apr 11, 2020');

//返回15天前0点的时间戳
TimeHelper::beforeDay(15,null,true);

//返回15天后的时间戳
TimeHelper::afterDay(15);

//返回5个月后的时间戳
TimeHelper::afterMonth(5);

//将任意格式的时间转换为指定格式
TimeHelper::format('Y-m-d H:i:s','May 3, 2022');

//将任意时间类型的字符串转为时间戳
TimeHelper::toTimestamp('Apr 11, 2020');

//获取当前时间
TimeHelper::now();
```

更多用法请移步[使用文档](https://time.0x1.site/)

🚀 安装
----

[](#-安装)

通过 Composer 导入类库

```
composer require zjkal/time-helper
```

🌈 使用文档
------

[](#-使用文档)

查看[使用文档](https://time.0x1.site/)

📃 更新日志
------

[](#-更新日志)

查看[更新日志](https://time.0x1.site/appendices/chang-log.html)

😎 开发者们
------

[](#-开发者们)

    [ ![zjkal](https://avatars.githubusercontent.com/u/15082976?v=4)
 **zjkal** ](https://github.com/zjkal)   [ ![miss-sugar](https://avatars.githubusercontent.com/u/121731951?v=4)
 **miss-sugar** ](https://github.com/miss-sugar)   [ ![iuyes](https://avatars.githubusercontent.com/u/2977219?v=4)
 **李云龙** ](https://github.com/iuyes)   [ ![ageChen](https://avatars.githubusercontent.com/u/71121939?v=4)
 **ageChen** ](https://github.com/ageChen)   [ ![dkoin](https://avatars.githubusercontent.com/u/5207234?v=4)
 **dkoin** ](https://github.com/dkoin)   [ ![wolf-leo](https://avatars.githubusercontent.com/u/37436228?v=4)
 **wolfcode** ](https://github.com/wolf-leo)   ❤️ 赞助
-----

[](#️-赞助)

非常感谢 Jetbrains 为我提供的 IDE 开源许可，让我完成此项目和其他开源项目上的开发工作。

[![](https://camo.githubusercontent.com/3cf726e7cdadba47755b7f7ea4227945a92a2fa48aadf4a2573140ec6501c989/68747470733a2f2f7265736f75726365732e6a6574627261696e732e636f6d2f73746f726167652f70726f64756374732f636f6d70616e792f6272616e642f6c6f676f732f6a625f6265616d2e737667)](https://www.jetbrains.com/?from=github)

🐧 扫以下二维码加入 QQ 频道
----------------

[](#-扫以下二维码加入-qq-频道)

[ ![QQ频道-世界上最好的编程语言](https://camo.githubusercontent.com/22cd029ebd45e77c7417ee3fbc3f0e68870caf9dfc55016d3a94023dbbd24fff/68747470733a2f2f63646e2e3078312e736974652f7172636f64652d717170642e706e67)](https://pd.qq.com/s/7h2hvcuxs)📖 开源协议
------

[](#-开源协议)

TimeHelper 遵循[MIT 开源协议](https://github.com/zjkal/time-helper/blob/main/LICENSE), 意味着您无需任何授权, 即可免费将 TimeHelper 应用到您的项目中

###  Health Score

57

—

FairBetter than 98% of packages

Maintenance93

Actively maintained with recent releases

Popularity46

Moderate usage in the ecosystem

Community25

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.3% 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 ~48 days

Recently: every ~95 days

Total

29

Last Release

41d ago

PHP version history (2 changes)v1.0PHP &gt;=7.0

v1.1.2PHP &gt;=7.1

### Community

Maintainers

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

---

Top Contributors

[![zjkal](https://avatars.githubusercontent.com/u/15082976?v=4)](https://github.com/zjkal "zjkal (386 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (20 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (5 commits)")[![iuyes](https://avatars.githubusercontent.com/u/2977219?v=4)](https://github.com/iuyes "iuyes (2 commits)")[![miss-sugar](https://avatars.githubusercontent.com/u/121731951?v=4)](https://github.com/miss-sugar "miss-sugar (2 commits)")[![dkoin](https://avatars.githubusercontent.com/u/5207234?v=4)](https://github.com/dkoin "dkoin (1 commits)")[![wolf-leo](https://avatars.githubusercontent.com/u/37436228?v=4)](https://github.com/wolf-leo "wolf-leo (1 commits)")[![ageChen](https://avatars.githubusercontent.com/u/71121939?v=4)](https://github.com/ageChen "ageChen (1 commits)")

---

Tags

composerdatehelperslibrariesphptimetoolphphelperdatetimetimedatezjkal

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/zjkal-time-helper/health.svg)

```
[![Health](https://phpackages.com/badges/zjkal-time-helper/health.svg)](https://phpackages.com/packages/zjkal-time-helper)
```

###  Alternatives

[kartik-v/php-date-formatter

A Javascript datetime formatting and manipulation library using PHP date-time formats.

461.6M3](/packages/kartik-v-php-date-formatter)[dater/dater

Compact PHP library for working with date/time in different formats &amp; timezones.

14283.6k](/packages/dater-dater)[danielstjules/php-pretty-datetime

Generates human-readable strings for PHP DateTime objects

5797.0k](/packages/danielstjules-php-pretty-datetime)[advmaker/carbon-period

Extension of nesbot/carbon plugin, to work with date period

10116.0k](/packages/advmaker-carbon-period)

PHPackages © 2026

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