krzysztofzylka / date
日期库
1.0.1
2024-02-03 16:13 UTC
Requires
- php: >=8.0
README
composer require krzysztofzylka/date
创建实例
$date = new \Krzysztofzylka\Date\Date();
静态方法
获取简单日期
\Krzysztofzylka\Date\Date::getSimpleDate() \Krzysztofzylka\Date\Date::getSimpleDate(true) //with microseconds
获取到日期的秒数
\Krzysztofzylka\Date\Date::getSecondsToDate($seconds)
创建实例
\Krzysztofzylka\Date\Date::create(null) \Krzysztofzylka\Date\Date::create(time()) \Krzysztofzylka\Date\Date::create(date('Y-m-d H:i:s'))
方法
获取时间
$date->getTime()
获取日期
$date->getDate()
设置日期
$date->set(null) $date->set(time()) $date->set(date('Y-m-d H:i:s'))
更改默认格式 (Y-m-d H:i:s)
$date->format($format)
向日期添加秒
$date->addSecond($seconds)
向日期添加分钟
$date->addMinute($minutes)
向日期添加小时
$date->addHour($hours)
向日期添加天
$date->addDay($days)
向日期添加月
$date->addMonth($months, $fixCalculate)
示例
$date = new \Krzysztofzylka\Date\Date('2024-03-31'); $date->addMonth(1); echo $date->getDate('Y-m-d'); //2024-04-30 $date = new \Krzysztofzylka\Date\Date('2024-03-31', false); $date->addMonth(1); echo $date->getDate('Y-m-d'); //2024-05-01
向日期添加年
$date->addYear($years)
从日期中减去秒
$date->subSecond($seconds)
从日期中减去分钟
$date->subMinute($minutes)
从日期中减去小时
$date->subHour($hours)
从日期中减去天
$date->subDay($days)
从日期中减去月
$date->subMonth($months)
从日期中减去年
$date->subYear($years)
工具
获取日期月差异
\Krzysztofzylka\Date\DateUtils::dateMonthDifference($dateFrom, $dateTo)