wikimedia/timestamp
Composer 安装命令:
composer require wikimedia/timestamp
包简介
Creation, parsing, and conversion of timestamps
README 文档
README
Convertible Timestamp for PHP
This library provides a convenient wrapper around DateTime to create, parse, and format timestamps.
Additional documentation about the library can be found on MediaWiki.org.
Supported formats
On input, the following formats are recognized:
- A subset of ISO 8601 basic and extended formats:
- Years before 0000 or after 9999 are not supported.
- Week and ordinal dates are not supported.
- Accuracy to seconds is required. Fractions of a second are supported to microsecond resolution.
- If the timezone is omitted, UTC is assumed.
- As an extension, the 'T' may be replaced with a single space.
- As a signed integer (up to 13 digits) representing seconds since the Unix epoch.
- Optionally with decimal seconds to microsecond resolution, using '.' as the decimal separator.
- RFC 2822 format, including obsolete syntax.
- CFWS tokens are not fully supported, use only FWS.
- Note, per the RFC, all military timezones are considered as -0000.
- As an extension, the timezone may be omitted entirely in which case UTC is assumed.
- As an extension, anything after the first semicolon in the string is ignored.
- RFC 850 format.
- asctime format.
- The
MW,DB,POSTGRES,ORACLE, andEXIFformats described below.
For output, the following conversions are predefined in TimestampFormat:
DB: MySQL datetime format: "2012-07-31 19:01:08"EXIF: Exif 2.2 format: "2012:07:31 19:01:08"ISO_8601: ISO 8601 expanded format: "2012-07-31T19:01:08Z"ISO_8601_BASIC: ISO 8601 basic format: "20120731T190108Z"MW: A 14-digit string: "20120731190108"ORACLE: A default Oracle timestamp format: "31-07-2012 19:01:08.000000"POSTGRES: PostgreSQL default timestamptz format: "2012-07-31 19:01:08+00"RFC2822: RFC 2822 format using an obsolete timezone: "Tue, 31 Jul 2012 19:01:08 GMT"UNIX: Seconds since the Unix epoch (1970-01-01T00:00:00Z): "1343761268".UNIX_MICRO: Seconds since the Unix epoch with microseconds: "1343761268.000000".
For backward compatibility with wikimedia/timestamp v5.0 and earlier,
there are also global constants defined for these formats. The
constants have names beginning with TS_, for example TS_UNIX.
Use of these constants is discouraged in new code.
Usage
$ts = new ConvertibleTimestamp( '2012-07-31T19:01:08Z' ); $formatted = $ts->getTimestamp( TimestampFormat::UNIX ); // Shorthand $formatted = ConvertibleTimestamp::convert( TimestampFormat::UNIX, '2012-07-31T19:01:08Z' ); // Format using PHP date formatting codes $formatted = $ts->format( 'Y-m-d H:i:s O' );
Running tests
composer install --prefer-dist
composer test
Releasing a new version
This package uses wikimedia/update-history and its conventions.
See https://www.mediawiki.org/wiki/UpdateHistory for details.
wikimedia/timestamp 适用场景与选型建议
wikimedia/timestamp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 738.59k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2016 年 09 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 wikimedia/timestamp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wikimedia/timestamp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 738.59k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 29
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2016-09-29