sunfoxcz / date-utils
用于简化日期区间操作的库。
v3.0.0
2022-10-08 22:57 UTC
Requires
- php: ^8.0
Requires (Dev)
- ext-iconv: *
- ext-json: *
- nette/tester: ^2.4
- phpstan/phpstan: ^0.12
- sunfoxcz/coding-standard: dev-master
This package is auto-updated.
Last update: 2024-09-19 00:20:37 UTC
README
用于简化日期区间操作的库。
安装
composer require sunfoxcz/date-utils
使用
DateIntervalFactory
<?php declare(strict_types=1); use Sunfox\DateUtils\DateTime; use Sunfox\DateUtils\DateIntervalFactory; $start = new DateTime('2015-01-01'); $end = new DateTime('2015-12-31'); $months = DateIntervalFactory::create($start, $end, DateIntervalFactory::MONTH, 1, [ 'incomes' => [], 'expenses' => [], ]); foreach ($months as $k => $month) { echo "{$k}: " . $month->date->format('Y-m-d') . PHP_EOL; }
SpentTime
<?php declare(strict_types=1); use Sunfox\DateUtils\SpentTime; $spentTime = new SpentTime('1h30m'); echo (string) $spentTime; // 01:30:00 echo $spentTime->getTotalHours(); // 1,5 echo $spentTime->getTotalMinutes(); // 90 echo $spentTime->getTotalSeconds(); // 5400
更多用法请查看测试目录。