avadim/chrono
Composer 安装命令:
composer require avadim/chrono
包简介
Extends the features of PHP DateTime classes
README 文档
README
Extends the features of PHP DateTime classes
Create Chrono\DateTime object
use avadim\Chrono\Chrono; // Create date from any type: // string - any datetime format // integer - unix timestamp // DateTime - instance of standard php class // Chrono\Chrono - instance of class // You also can set time zone $date = Chrono::createDate('now', '+3'); // Current date and time $date = Chrono::now(); // Current date and time in Africa/Dakar timezone $date = Chrono::now('Africa/Dakar'); // Current date and time with timezone offset -5 $date = Chrono::now(-5); // Current date with zero time $date = Chrono::today(); // Create date corresponding to the arguments given $date = Chrono::make(1984, 23, 2, 17); // $date is '1094-23-02 17:00:00 $date = Chrono::make(1984); // $date is '1994-01-01 00:00:00' // Create date from arguments with current time $date = Chrono::createFromDate(1984); // if current datetime is '2020-07-17 11:34:48' then $date is '1984-07-17 11:34:48' // Create current date with time from arguments $date = Chrono::createFromTime(1, 59, 7, '-5');
Create period
use avadim\Chrono\Chrono; echo '<h3>Sequence</h3>'; foreach (Chrono::createPeriod('now', '+1 week')->sequenceOfDays() as $oDate) { echo $oDate, '<br>'; }
Date operations
use avadim\Chrono\Chrono; // Adds any interval (an amount of days, months, years, hours, minutes and seconds) to given date $date = Chrono::dateAdd('now', '1 week'); // Subtracts any interval from given date $date = Chrono::dateSub('1742-11-28', 'P2Y1M'); // The same as Chrono::dateAdd() but returns formatted date. String '@999' is a UNIX timestamp $dateString = Chrono::dateAddFormat('@946684800', '1 year + 2 months + 13 days', 'D M j, Y G:i:s T'); // The same as Chrono::dateAdd() but returns formatted date $dateString = Chrono::dateSubFormat('Mar 14, 1987', 'P1Y', 'm/d/Y');
Compare dates
use avadim\Chrono\Chrono; // Calculates the difference between two dates $date1 = new \DateTime('1985-01-20'); $date2 = new \DateTime('1997-03-27'); $int = Chrono::dateDiffSeconds($date1, 'now'); $int = Chrono::dateDiffMinutes($date1, $date2); $int = Chrono::dateDiffHours($date1, $date2); $int = Chrono::dateDiffDays($date1, 'today'); // Compare two dates // You can use operators: '<', 'lt', '<=', 'le', 'lte', '=', '==', 'eq', '!=', '<>', 'ne', '>=', 'gte', 'ge', '>', 'gt' $bool = Chrono::compare($date1, '>=', $date2); // Determines if the passed date is between two other dates $bool = Chrono::between('1990-12-31', $date1, $date2);
avadim/chrono 适用场景与选型建议
avadim/chrono 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 100 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 11 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「time」 「date」 「timezone」 「datetime」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 avadim/chrono 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 avadim/chrono 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 avadim/chrono 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Tools to convert between .NET and PHP date formats
Adds the EDTF data type to Wikibase
Datetime helpers for timezone handling
A custom Doctine DBAL type to use PHP DateTime objects set to the system's default timezone.
A powerful event calendar Tool for Laravel's Nova 5.
Official PHP SDK for the IPGeolocation.io IP Location API with single and bulk lookup support.
统计信息
- 总下载量: 100
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-11-05