laborci / valentine-date
此包的最新版本(1.0)没有可用的许可信息。
1.0
2019-02-14 15:45 UTC
Requires
- php: >=7.0
This package is auto-updated.
Last update: 2024-09-15 04:31:38 UTC
README
缺失日期类的实现
只读属性
int $year
int $month
int $day
string $month00
// the month with leading zeroes (01-12)
string $day00
// the day with leading zeroes (01-31)
int $dayOfWeek
// starts with Sunday indexed from 0
int $dayOfWeekISO
// starts with Monday indexed from 0
int $dayOfWeekM0
// starts with Monday indexed from 0
int $dayOfWeekM1
// starts with Monday indexed from 1
int $dayOfWeekS0
// starts with Sunday indexed from 0
int $dayOfWeekS1
// starts with Sunday indexed from 1
int $week
// ISO-8601 week number of year, weeks starting on Monday
int $yearOfWeek
// the year of week can be different from the date’s year
bool $isLeapYear
// whether it's a leap year
int $dayOfYear
// the day of the year (starting from 0)
int $days
// number of days in the given month
实例化
public function __construct(string $date = 'today', $format = 'Y-m-d')
// https://php.ac.cn/manual/en/datetime.createfromformat.php
static createFromFormat(string $date = 'today', $format = 'Y-m-d'): self
static createFromDateTime(\DateTime $date): self
static createFromWeek($year, $week, $day = 1): self
创建副本
copyMutable(): Date
copyImmutable(): DateImmutable
copy(): self
转换为字符串
format($format):string
__toString():string // Y-m-d
比较两个日期
diff(Date|DateImmutable $diff):\DateInterval
diffDays(Date|DateImmutable $diff):int
// returns signed integer
获取 \DateTime 对象
- Date 返回嵌入的 \DateTime 对象
- DateImmutable 返回 \DateTime 对象的副本
getDate(): \DateTime;
修改日期(DateImmutable 中不可用)
modify($modify): $this;
// https://php.ac.cn/manual/en/datetime.modify.php
add(int $year = 0, int $month = 0, int $day = 0, int $week = 0): $this;
sub(int $year = 0, int $month = 0, int $day = 0, int $week = 0): $this;
// adds and subtracts years, months, days, weeks from/to the current date
setDate($year = null, $month = null, $day = null): $this
setWeek($week = null, $day = null, $year = null): $this;
// if any argument’s value is null, it refers the current year, day, week, month