robier / date
ISO 8601标准日期的简单实现
v1.1.0
2017-08-07 08:55 UTC
Requires
- php: ^7.1
Requires (Dev)
- codeclimate/php-test-reporter: ^0.4.4
- friendsofphp/php-cs-fixer: ^2.3
- phpunit/phpunit: ^6.1
This package is auto-updated.
Last update: 2024-09-13 05:14:35 UTC
README
ISO 8601标准日期的简单实现。
简介
日期类遵循ISO 8601标准来表示日期。
同时允许轻松获取两个日期的范围。
安装
您可以使用composer安装此库。
composer require robier/date
要求
此库需要PHP 7.1。
概述
此库包含3个类
Date
- 实际日期的表示Date\Factory
- 用于以不同方式创建Date
对象的工厂Date\Range
- 表示两个日期之间范围的生成器
示例
创建新的Date实例(以各种方式获取1991-11-14的日期)
use Robier\Date; $date = new Date(1991, 11, 14); // or $date = Date/Factory::new(1991, 11, 14); // or $date = Date/Factory::dateTime(DateTime::createFromFormat('Y-m-d', '1991-11-14')); // or $date = Date/Factory::string('1991-11-14'); // or $date = Date/Factory::iso(1991, 46, 4);
获取今天的日期
$today = Date/Factory::today();
获取明天的日期
$tomorrow = Date/Factory::tomorrow(); // or $tomorrow = Date/Factory::today()->next();
获取昨天的日期
$yesterday = Date/Factory::yesterday(); // or $yesterday = Date/Factory::today()->previous();
获取给定日期之后的任何日期(例如,1991-11-14之后的5天)
$date = new Date(1991, 11, 14); $date->next(5);
获取给定日期之前的任何日期(例如,1991-11-14之前的6天)
$date = new Date(1991, 11, 14); $date->previous(6);
两个日期之间的范围(例如,获取1991-11-14和1991-12-01之间的日期)
$start = new Date(1991, 11, 14); $end = new Date(1991, 12, 1); $range = new Date\Range($start, $end); // or $range = $start->to($end);