arokettu/date

PHP的日期类(不含时间)

2.2.2 2024-07-28 19:08 UTC

This package is auto-updated.

Last update: 2024-08-28 19:20:18 UTC


README

PHP License GitLab CI Codecov

为PHP提供与纯日期(不含时间)交互的类。

安装

composer require arokettu/date

使用

<?php

use Arokettu\Date\Calendar;
use Arokettu\Date\Date;
use Arokettu\Date\JulianCalendar;
use Arokettu\Date\Month;

// creation
$date = Date::today(); // example: 2024-02-27
// or
$date = Calendar::create(2024, Month::February, 27);
// or
$date = Calendar::fromDateTime(new DateTime('Feb 27, 2024')); // truncates time
// or
$date = Calendar::parse('2024-02-27'); // Y-m-d is expected, years can be negative
// or
$date = Calendar::parseDateTimeString('Feb 27, 2024');

// alternative calendars
$date = JulianCalendar::parse('2024-02-14');

// getters
$date->getDay(); // 27
$date->getMonth(); // Month::February
$date->getMonthNumber(); // 2
$date->getYear(); // 2024
$date->getWeekDay(); // WeekDay::Tuesday
$date->getJulianDay(); // 2460368
$date->toDateTime(); // DateTimeImmutable('2024-02-27') // midnight in a default timezone
$date->toString(); // "2024-02-27"

// alternative calendar getters
$date->julian()->getDay(); // 14
$date->julian()->toString(); // "2024-02-14"

文档

请在此处阅读完整文档:https://sandfox.dev/php/date.html

在Read the Docs上也有:https://php-date.readthedocs.io/

支持

请在我们GitLab的主仓库中提交问题:https://gitlab.com/sandfox/php-uuid/-/issues

在Gitter的房间中随时提问:https://gitter.im/arokettu/community

许可证

此库作为开源软件,在MIT许可证的条款下提供。