psx/datetime
Composer 安装命令:
composer require psx/datetime
包简介
PHP port of the Java JSR310 time API
README 文档
README
PHP port of the Java JSR 310 time API. This package provides the following classes:
| Class | Description |
|---|---|
| Duration | A time-based amount of time, such as '34.5 seconds' |
| LocalDate | A date without a time-zone in the ISO-8601 calendar system, such as 2007-12-03 |
| LocalDateTime | A date-time without a time-zone in the ISO-8601 calendar system, such as 2007-12-03T10:15:30 |
| LocalTime | A time without a time-zone in the ISO-8601 calendar system, such as 10:15:30 |
| Period | A date-based amount of time in the ISO-8601 calendar system, such as '2 years, 3 months and 4 days' |
| DayOfWeek | A day-of-week, such as 'Tuesday' |
| Month | A month-of-year, such as 'July' |
All classes are immutable, this means that every modification to the object returns a new instance containing the modification.
Usage
The following snippet shows some examples how you can use the API.
<?php use PSX\DateTime\Duration; use PSX\DateTime\LocalDate; use PSX\DateTime\LocalDateTime; use PSX\DateTime\LocalTime; use PSX\DateTime\Period; // date time $dateTime = LocalDateTime::parse('2023-03-22T22:56:00Z'); $dateTime = LocalDateTime::of(2023, 3, 22, 22, 56, 0); $dateTime->getYear(); // 2023 $dateTime->getMonth(); // Month::MARCH $dateTime->getMonthValue(); // 3 $dateTime->getDayOfMonth(); // 22 $dateTime->getDayOfWeek(); // 3 $dateTime->getHour(); // 22 $dateTime->getMinute(); // 56 $dateTime->getSecond(); // 0 $dateTime->plusDays(1); $dateTime->minusDays(1); $dateTime->withDayOfMonth(1); echo $dateTime->toString(); // 2016-03-28T23:27:00Z // date $date = LocalDate::parse('2023-03-22'); $date = LocalDate::of(2023, 3, 22); echo $date->toString(); // 2023-03-22 // time $time = LocalTime::parse('23:27:00'); $time = LocalTime::of(23, 27, 0); echo $time->toString(); // 23:27:00 // period $period = Period::parse('P1D'); $period = Period::of(1, 0, 0); echo $period->toString(); // P1D // duration $duration = Duration::parse('P1H'); $duration = Duration::of(1, 0, 0); echo $duration->toString(); // PT1H
psx/datetime 适用场景与选型建议
psx/datetime 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 242.59k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2016 年 03 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「time」 「date」 「date-time」 「rfc3339」 「JSR310」 「joda」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 psx/datetime 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 psx/datetime 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 psx/datetime 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A comprehensive collection of PHP utility functions for array manipulation, string operations, date handling, HTML generation, form building, validation, and more. Modern PHP 8.2+ library with full type safety.
Tools to convert between .NET and PHP date formats
Adds the EDTF data type to Wikibase
A powerful event calendar Tool for Laravel's Nova 5.
Date component is a set of methods to help with the manipulation of dates.
Bureaux A Partager Edit - Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
统计信息
- 总下载量: 242.59k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 28
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2016-03-31