time-helper:PHP时间日期处理助手,支持友好格式、时间计算与节假日判断

一个简单快捷的PHP日期时间助手类库。

Branch1Tags31
FilesLast commitLast update
10 days ago
2 days ago
2 days ago
10 days ago
5 months ago
2 years ago
2 days ago
10 days ago
5 months ago
10 days ago
3 years ago
3 months ago
5 months ago
3 years ago

TimeHelper

中文 | English

License PHP Version Require Latest Stable Version Total Downloads GitHub Workflow Status

TimeHelper is a simple and easy-to-use PHP date and time helper library that can quickly implement common date and time operations, such as getting seconds of a specified time, getting friendly time formats, judging time ranges, calculating time differences, returning timestamps N hours/days/weeks/months/years before or after, etc.

🧩 Features

  • Simple and easy to use: No dependencies, ready to use
  • Simplify complexity: All methods can accept any type of date and time format or timestamp
  • Fast and efficient: All operations can be completed with just one static method

🎁 Examples

//Check if the specified date is a Chinese workday
ChinaHoliday::isWorkday('2023-01-23');

//Check if the specified date is a Chinese holiday
ChinaHoliday::isHoliday(1646360133);

//Return friendly time format, such as: just now, N seconds ago, N minutes ago, N hours ago, etc.
TimeHelper::toFriendly('2022-3-2 10:15:33');
//Return friendly time format (English)
TimeHelper::toFriendly(1646186290, 'en');

//Check if the date is today
TimeHelper::isToday('2020-4-10 23:01:11');

//Check if the date is a weekday (Monday to Friday)
TimeHelper::isWeekday('2023-03-08');

//Calculate the number of days between two dates
TimeHelper::diffDays('2022-4-10 23:01:11','Apr 11, 2020');

//Return timestamp of 15 days ago at 0:00
TimeHelper::beforeDay(15,null,true);

//Return timestamp of 15 days later
TimeHelper::afterDay(15);

//Return timestamp of 5 months later
TimeHelper::afterMonth(5);

//Convert any format time to specified format
TimeHelper::format('Y-m-d H:i:s','May 3, 2022');

//Convert any time type string to timestamp
TimeHelper::toTimestamp('Apr 11, 2020');

//Get current time
TimeHelper::now();

//Get this month's start and end timestamps, including the start and excluding the end
$range = TimeRange::month();

//Get last month's start and end timestamps
TimeRange::month(null, -1);

//Check if the time is within the specified range
TimeRange::contains('2026-10-27', '2026-10-01', '2026-11-01');

//Check if the date is valid
TimeHelper::isValidDate('2026-02-31'); // false

//Parse the date using the specified format
TimeHelper::parseExact('03/04/2026', 'd/m/Y'); // April 3, 2026

For more usage, please refer to Documentation

🚀 Installation

Import the library via Composer

composer require zjkal/time-helper

🌈 Documentation

View Documentation

📃 Changelog

View Changelog

😎 Developers

zjkal
zjkal
miss-sugar
miss-sugar
iuyes
Li Yunlong
ageChen
ageChen
dkoin
dkoin
wolf-leo
wolfcode

❤️ Sponsor

Many thanks to Jetbrains for providing me with an IDE open source license, allowing me to complete this project and other open source projects.

📖 License

TimeHelper follows the MIT License, which means you can freely use TimeHelper in your projects without any authorization.