CakePHP
  • 文档
    • 书籍
    • API
    • 视频
    • 报告安全问题
    • 隐私政策
    • 标识与商标
  • 商业解决方案
  • 礼品
  • 公路旅行
  • 团队
  • 社区
    • 社区
    • 参与进来
    • 问题 (Github)
    • 面包店
    • 特色资源
    • 培训
    • 聚会
    • 我的 CakePHP
    • CakeFest
    • 通讯
    • 领英
    • YouTube
    • 脸书
    • 推特
    • Mastodon
    • 帮助与支持
    • 论坛
    • Stack Overflow
    • IRC
    • Slack
    • 付费支持
CakePHP

C Chronos 3.x API

  • 项目
    • Chronos
      • CakePHP
      • Chronos
      • Elastic Search
      • 队列
  • 版本
    • 3.x
      • 3.x
      • 2.x
      • 1.x

命名空间

  • Cake\Chronos

ChronosDate 类

一个不可变的日期对象。

当您想表示一个日历日期并忽略时间时,此类很有用。这意味着时区更改不会产生影响,因为日历日期在每个时区中都存在于各自的日期中。

命名空间: Cake\Chronos

常量

  • string
    DEFAULT_TO_STRING_FORMAT ¶
    'Y-m-d'

    类型转换时,用于 __toString 方法的默认格式。

属性摘要

  • $age public @property-read
    int

    使用默认参数执行 diffInYears()。

  • $day public @property-read
    int<1, 31>
  • $dayOfWeek public @property-read
    int<1, 7>

    1(星期一)到 7(星期日)

  • $dayOfYear public @property-read
    int<0, 365>

    0 到 365

  • $days protected static
    array

    一周中每一天的名称。

  • $daysInMonth public @property-read
    int<1, 31>

    给定月份的天数

  • $diffFormatter protected static
    Cake\Chronos\DifferenceFormatterInterface|null

    差异格式化对象的实例。

  • $half public @property-read
    int<1, 2>

    一年的前半部分,1 表示 1 月到 6 月,2 表示 7 月到 12 月。

  • $lastErrors protected static
    array|false

    上次调用 createFromFormat() 时的错误。

  • $month public @property-read
    int<1, 12>
  • $native protected
    DateTimeImmutable
  • $quarter public @property-read
    int<1, 4>

    此实例的季度,1 - 4

  • $toStringFormat protected static
    string

    类型转换时,用于 __toString 方法的格式。

  • $weekOfMonth public @property-read
    int<1, 5>

    1 到 5

  • $weekOfYear public @property-read
    int<1, 53>

    ISO-8601 年的周数,周从星期一开始

  • $year public @property-read
    int
  • $yearIso public @property-read
    int

方法摘要

  • __construct() public

    创建一个新的不可变日期实例。

  • __debugInfo() public

    返回用于调试的属性。

  • __get() public

    获取对象的一部分

  • __isset() public

    检查对象上是否存在属性

  • __toString() public

    返回由 setToStringFormat() 指定的格式化字符串或默认的 DEFAULT_TO_STRING_FORMAT 格式。

  • add() public

    将一个间隔添加到日期

  • addDays() public

    将天数添加到实例中。正 $value 向前移动,而负 $value 向后移动。

  • addMonths() public

    将月数添加到实例中。正 $value 向前移动,而负 $value 向后移动。

  • addMonthsWithOverflow() public

    将带有溢出的月数添加到实例中。正 $value 向前移动,而负 $value 向后移动。

  • addWeekdays() public

    将工作日添加到实例中。正 $value 向前移动,而负 $value 向后移动。

  • addWeeks() public

    将周数添加到实例中。正 $value 向前移动,而负 $value 向后移动。

  • addYears() public

    将年数添加到实例中。正 $value 向前移动,而负 $value 向后移动。

  • addYearsWithOverflow() public

    将带有溢出的年数添加到实例中。正 $value 向前移动,而负 $value 向后移动。

  • between() public

    确定实例是否介于另外两个实例之间

  • closest() public

    获取距实例最近的日期。

  • create() public static

    从特定日期创建一个实例。

  • createFromArray() public static

    从日期值的数组中创建一个实例。

  • createFromFormat() public static

    从特定格式创建一个实例

  • createNative() protected

    初始化 PHP DateTimeImmutable 对象。

  • day() public

    设置实例的日期

  • diff() public

    返回此实例和目标之间的差异。

  • diffFiltered() public

    使用过滤器可调用函数获取给定间隔的差异

  • diffForHumans() public

    以人类可读的格式获取差异。

  • diffFormatter() public static

    获取差异格式化程序实例或覆盖当前实例。

  • diffInDays() public

    获取天数的差异

  • diffInDaysFiltered() public

    使用过滤器可调用函数获取天数的差异

  • diffInMonths() public

    获取月数的差异

  • diffInWeekdays() public

    获取工作日的差异

  • diffInWeekendDays() public

    使用过滤器获取周末的差异

  • diffInWeeks() public

    获取周数的差异

  • diffInYears() public

    获取年数的差异

  • endOfCentury() public

    将日期重置为世纪末,时间重置为 23:59:59

  • endOfDecade() public

    将日期重置为十年末

  • endOfMonth() public

    将日期重置为月底

  • endOfWeek() public

    将日期重置为周末(在 $weekEndsAt 中定义),时间重置为 23:59:59

  • endOfYear() public

    将日期重置为年底

  • equals() public

    确定实例是否等于另一个实例

  • farthest() public

    获取距实例最远的日期。

  • firstOfMonth() public

    修改为当前月份中给定一周的第一次出现。如果没有提供 dayOfWeek,则修改为当前月份的第一天。使用提供的常量来指示所需的 dayOfWeek,例如 Chronos::MONDAY。

  • firstOfQuarter() public

    修改为当前季度中给定一周的第一次出现。如果没有提供 dayOfWeek,则修改为当前季度的第一天。使用提供的常量来指示所需的 dayOfWeek,例如 Chronos::MONDAY。

  • firstOfYear() public

    修改为当前年份中给定一周的第一次出现。如果没有提供 dayOfWeek,则修改为当前年份的第一天。使用提供的常量来指示所需的 dayOfWeek,例如 Chronos::MONDAY。

  • format() public

    根据 DateTimeImmutable::format() 返回格式化的日期字符串。

  • getLastErrors() public static

    返回上次调用 createFromFormat() 时的解析警告和错误。

  • greaterThan() public

    确定实例是否大于(在)另一个实例之后

  • greaterThanOrEquals() public

    确定实例是否大于(在)或等于另一个实例之后

  • isFirstHalf() public

    确定实例是否在一年上半年的范围内

  • isFriday() public

    检查这一天是否为星期五。

  • isFuture() public

    确定实例是否在未来,即大于(在)现在之后

  • isLastMonth() public

    确定实例是否在过去的一个月内

  • isLastWeek() public

    确定实例是否在过去的一周内

  • isLastYear() public

    确定实例是否在过去的一年内

  • isLeapYear() public

    确定实例是否是闰年

  • isMonday() public

    检查这一天是否是星期一。

  • isNextMonth() public

    确定实例是否在接下来的一个月内

  • isNextWeek() public

    确定实例是否在接下来的一个星期内

  • isNextYear() public

    确定实例是否在接下来的一个年内

  • isPast() public

    确定实例是否在过去,即小于(早于)现在

  • isSaturday() public

    检查这一天是否是星期六。

  • isSecondHalf() public

    确定实例是否在今年的下半年

  • isSunday() public

    检查这一天是否是星期日。

  • isThursday() public

    检查这一天是否是星期四。

  • isToday() public

    确定实例是否为今天

  • isTomorrow() public

    确定实例是否为明天

  • isTuesday() public

    检查这一天是否是星期二。

  • isWednesday() public

    检查这一天是否是星期三。

  • isWeekday() public

    确定实例是否是工作日

  • isWeekend() public

    确定实例是否是周末

  • isWithinNext() public

    如果此实例将在指定的时间间隔内发生,则返回 true

  • isYesterday() public

    确定实例是否为昨天

  • lastOfMonth() public

    修改为当前月份中给定一周的最后一次出现。如果没有提供 dayOfWeek,则修改为当前月份的最后一天。使用提供的常量来指示所需 dayOfWeek,例如 Chronos::MONDAY。

  • lastOfQuarter() public

    修改为当前季度中给定一周的最后一次出现。如果没有提供 dayOfWeek,则修改为当前季度的最后一天。使用提供的常量来指示所需 dayOfWeek,例如 Chronos::MONDAY。

  • lastOfYear() public

    修改为当前年份中给定一周的最后一次出现。如果没有提供 dayOfWeek,则修改为当前年份的最后一天。使用提供的常量来指示所需 dayOfWeek,例如 Chronos::MONDAY。

  • lessThan() public

    确定实例是否小于(早于)另一个实例

  • lessThanOrEquals() public

    确定实例是否小于(早于)或等于另一个实例

  • modify() public

    根据 DateTimeImmutable::modifier() 创建一个新的实例,其中日期已修改。

  • month() public

    设置实例的月份

  • next() public

    修改为给定一周的下次出现。如果没有提供 dayOfWeek,则修改为当前一周的下次出现。使用提供的常量来指示所需 dayOfWeek,例如 Chronos::MONDAY。

  • notEquals() public

    确定实例是否不等于另一个实例

  • now() public static

    获取今天的日期。

  • nthOfMonth() public

    修改为当前月份中给定一周的指定次出现。如果计算出的出现超出了当前月份的范围,则返回 false 并且不会进行任何修改。使用提供的常量来指示所需 dayOfWeek,例如 Chronos::MONDAY。

  • nthOfQuarter() public

    修改为当前季度中给定一周的指定次出现。如果计算出的出现超出了当前季度的范围,则返回 false 并且不会进行任何修改。使用提供的常量来指示所需 dayOfWeek,例如 Chronos::MONDAY。

  • nthOfYear() public

    修改为当前年份中给定一周的指定次出现。如果计算出的出现超出了当前年份的范围,则返回 false 并且不会进行任何修改。使用提供的常量来指示所需 dayOfWeek,例如 Chronos::MONDAY。

  • parse() public static

    从字符串创建实例。这是构造函数的别名,它允许更好的流畅语法,因为它允许您执行 Chronos::parse('Monday next week')->fn() 而不是 (new Chronos('Monday next week'))->fn()

  • previous() public

    修改为给定一周的上次出现。如果没有提供 dayOfWeek,则修改为当前一周的上次出现。使用提供的常量来指示所需 dayOfWeek,例如 Chronos::MONDAY。

  • resetToStringFormat() public static

    将 __toString() 格式重置为 DEFAULT_TO_STRING_FORMAT。

  • setDate() public

    设置日期。

  • setISODate() public

    根据 ISO 8601 标准设置日期

  • setToStringFormat() public static

    设置 __toString() 格式。

  • startOfCentury() public

    将日期重置为世纪的第一天

  • startOfDecade() public

    将日期重置为十年的第一天

  • startOfMonth() public

    将日期重置为月份的第一天

  • startOfWeek() public

    将日期重置为一周的第一天(在 $weekStartsAt 中定义)

  • startOfYear() public

    将日期重置为年份的第一天

  • sub() public

    从日期中减去间隔。

  • subDays() public

    从实例中删除天数

  • subMonths() public

    从实例中删除月份

  • subMonthsWithOverflow() public

    将带有溢出的月数添加到实例中。正 $value 向前移动,而负 $value 向后移动。

  • subWeekdays() public

    从实例中删除工作日

  • subWeeks() public

    从实例中删除星期

  • subYears() public

    从实例中删除年份。

  • subYearsWithOverflow() public

    从实例中删除带有溢出的年份

  • toAtomString() public

    将实例格式化为 ATOM

  • toCookieString() public

    将实例格式化为 COOKIE

  • toDateString() public

    将实例格式化为日期

  • toDateTimeImmutable() public

    以午夜的 DateTimeImmutable 实例形式返回日期。

  • toDateTimeString() public

    将实例格式化为日期和时间

  • toDayDateTimeString() public

    使用星期、日期和时间格式化实例

  • toFormattedDateString() public

    将实例格式化为可读日期

  • toIso8601String() public

    将实例格式化为 ISO8601

  • toNative() public

    以午夜的 DateTimeImmutable 实例形式返回日期。

  • toQuarter() public

    返回季度

  • toRfc1036String() public

    将实例格式化为 RFC1036

  • toRfc1123String() public

    将实例格式化为 RFC1123

  • toRfc2822String() public

    将实例格式化为 RFC2822

  • toRfc3339String() public

    将实例格式化为 RFC3339

  • toRfc822String() public

    将实例格式化为 RFC822

  • toRfc850String() public

    将实例格式化为 RFC850

  • toRssString() public

    将实例格式化为 RSS

  • toTimeString() public

    将实例格式化为时间

  • toUnixString() public

    返回一个 UNIX 时间戳。

  • toW3cString() public

    将实例格式化为 W3C

  • toWeek() public

    返回 ISO 8601 年份的周数,星期一为一周的开始

  • today() public static

    获取今天的日期。

  • tomorrow() public static

    获取明天的日期。

  • wasWithinLast() public

    如果此实例发生在指定的时间间隔内,则返回 true

  • year() public

    设置实例的年份。

  • yesterday() public static

    获取昨天的日期。

方法详情

__construct() ¶ public

__construct(Cake\Chronos\ChronosDateDateTimeInterface|string $time = 'now', DateTimeZone|string|null $timezone = null)

创建一个新的不可变日期实例。

日期没有时间或时区组件。内部ChronosDate包装一个PHP DateTimeImmutable,但将修改限制在仅对日期值进行的操作。

默认情况下,日期将根据服务器的默认时区计算。可以使用timezone参数来使用不同的时区。时区在解析诸如today和yesterday之类的相对日期表达式时使用,但在解析诸如2022-01-01之类的值时不参与。

参数
Cake\Chronos\ChronosDateDateTimeInterface|string $time optional

固定或相对时间

DateTimeZone|string|null $timezone optional

用于“现在”的时区

__debugInfo() ¶ public

__debugInfo(): array

返回用于调试的属性。

返回
array

__get() ¶ public

__get(string $name): string|float|int|bool

获取对象的一部分

参数
string $name

要读取的属性名称。

返回
string|float|int|bool
抛出
InvalidArgumentException

__isset() ¶ public

__isset(string $name): bool

检查对象上是否存在属性

参数
string $name

要检查的属性名称。

返回
bool

__toString() ¶ public

__toString(): string

返回由 setToStringFormat() 指定的格式化字符串或默认的 DEFAULT_TO_STRING_FORMAT 格式。

返回
string

add() ¶ public

add(DateInterval $interval): static

将一个间隔添加到日期

对时间的任何更改将被忽略并重置为 00:00:00

参数
DateInterval $interval

要修改此日期的间隔。

返回
static

addDays() ¶ public

addDays(int $value): static

将天数添加到实例中。正 $value 向前移动,而负 $value 向后移动。

参数
int $value

要添加的天数。

返回
static

addMonths() ¶ public

addMonths(int $value): static

将月数添加到实例中。正 $value 向前移动,而负 $value 向后移动。

添加或减去月份时,如果结果时间是日期不存在,则此操作的结果始终是目标月份的最后一天。

示例

 (new Chronos('2015-01-03'))->addMonths(1); // Results in 2015-02-03

(new Chronos('2015-01-31'))->addMonths(1); // Results in 2015-02-28
参数
int $value

要添加的月份数。

返回
static

addMonthsWithOverflow() ¶ public

addMonthsWithOverflow(int $value): static

将带有溢出的月数添加到实例中。正 $value 向前移动,而负 $value 向后移动。

如果新的ChronosDate不存在,则天数溢出到下一个月。

示例

 (new Chronos('2012-01-30'))->addMonthsWithOverflow(1); // Results in 2013-03-01
参数
int $value

要添加的月份数。

返回
static

addWeekdays() ¶ public

addWeekdays(int $value): static

将工作日添加到实例中。正 $value 向前移动,而负 $value 向后移动。

参数
int $value

要添加的工作日数。

返回
static

addWeeks() ¶ public

addWeeks(int $value): static

将周数添加到实例中。正 $value 向前移动,而负 $value 向后移动。

参数
int $value

要添加的周数。

返回
static

addYears() ¶ public

addYears(int $value): static

将年数添加到实例中。正 $value 向前移动,而负 $value 向后移动。

如果新的ChronosDate不存在,则使用该月的最后一天而不是溢出到下一个月。

示例

 (new Chronos('2015-01-03'))->addYears(1); // Results in 2016-01-03

(new Chronos('2012-02-29'))->addYears(1); // Results in 2013-02-28
参数
int $value

要添加的年份数。

返回
static

addYearsWithOverflow() ¶ public

addYearsWithOverflow(int $value): static

将带有溢出的年数添加到实例中。正 $value 向前移动,而负 $value 向后移动。

如果新的ChronosDate不存在,则天数溢出到下一个月。

示例

 (new Chronos('2012-02-29'))->addYearsWithOverflow(1); // Results in 2013-03-01
参数
int $value

要添加的年份数。

返回
static

between() ¶ public

between(Cake\Chronos\ChronosDate $start, Cake\Chronos\ChronosDate $end, bool $equals = true): bool

确定实例是否介于另外两个实例之间

参数
Cake\Chronos\ChronosDate $start

目标范围的开始

Cake\Chronos\ChronosDate $end

目标范围的结束

bool $equals optional

是否包括范围的开始和结束

返回
bool

closest() ¶ public

closest(Cake\Chronos\ChronosDate $first, Cake\Chronos\ChronosDate $second, Cake\Chronos\ChronosDate ...$others): self

获取距实例最近的日期。

参数
Cake\Chronos\ChronosDate $first

要比较的实例。

Cake\Chronos\ChronosDate $second

要比较的实例。

Cake\Chronos\ChronosDate ...$others

要比较的其他实例。

返回
self

create() ¶ public static

create(int $year, int $month, int $day): static

从特定日期创建一个实例。

参数
int $year

用于创建实例的年份。

int $month

用于创建实例的月份。

int $day

用于创建实例的日期。

返回
static

createFromArray() ¶ public static

createFromArray(array<int|string> $values): static

从日期值的数组中创建一个实例。

允许的值

  • year
  • month
  • day
参数
array<int|string> $values

日期和时间值的数组。

返回
static

createFromFormat() ¶ public static

createFromFormat(string $format, string $time): static

从特定格式创建一个实例

参数
string $format

与date()兼容的格式字符串。

string $time

要解释的格式化日期字符串。

返回
static
抛出
InvalidArgumentException

createNative() ¶ protected

createNative(Cake\Chronos\ChronosDateDateTimeInterface|string $time, DateTimeZone|string|null $timezone): DateTimeImmutable

初始化 PHP DateTimeImmutable 对象。

参数
Cake\Chronos\ChronosDateDateTimeInterface|string $time

固定或相对时间

DateTimeZone|string|null $timezone

用于“现在”的时区

返回
DateTimeImmutable

day() ¶ public

day(int $value): static

设置实例的日期

参数
int $value

日期值。

返回
static

diff() ¶ public

diff(Cake\Chronos\ChronosDate $target, bool $absolute = false): DateInterval

返回此实例和目标之间的差异。

参数
Cake\Chronos\ChronosDate $target

目标实例

bool $absolute optional

间隔是否强制为正

返回
DateInterval

diffFiltered() ¶ public

diffFiltered(DateInterval $interval, callable $callback, Cake\Chronos\ChronosDate|null $other = null, bool $absolute = true, int $options = 0): int

使用过滤器可调用函数获取给定间隔的差异

参数
DateInterval $interval

要遍历的间隔

callable $callback

用于过滤的回调。

Cake\Chronos\ChronosDate|null $other optional

要从中进行差别的实例。

bool $absolute optional

获取差异的绝对值

int $options optional

DatePeriod 选项,{@see https://php.ac.cn/manual/en/class.dateperiod.php}

返回
int

diffForHumans() ¶ public

diffForHumans(Cake\Chronos\ChronosDate|null $other = null, bool $absolute = false): string

以人类可读的格式获取差异。

当将过去的值与默认的现在进行比较时:5 个月前

当将未来的值与默认的现在进行比较时:5 个月后

当将过去的值与另一个值进行比较时:5 个月前

当将未来的值与另一个值进行比较时:5 个月后

参数
Cake\Chronos\ChronosDate|null $other optional

要比较的日期时间。

bool $absolute optional

删除差异修饰符 ago、after 等

返回
string

diffFormatter() ¶ public static

diffFormatter(Cake\Chronos\DifferenceFormatterInterface|null $formatter = null): Cake\Chronos\DifferenceFormatterInterface

获取差异格式化程序实例或覆盖当前实例。

参数
Cake\Chronos\DifferenceFormatterInterface|null $formatter optional

设置时的格式器实例。

返回
Cake\Chronos\DifferenceFormatterInterface

diffInDays() ¶ public

diffInDays(Cake\Chronos\ChronosDate|null $other = null, bool $absolute = true): int

获取天数的差异

参数
Cake\Chronos\ChronosDate|null $other optional

要从中进行差别的实例。

bool $absolute optional

获取差异的绝对值

返回
int

diffInDaysFiltered() ¶ public

diffInDaysFiltered(callable $callback, Cake\Chronos\ChronosDate|null $other = null, bool $absolute = true, int $options = 0): int

使用过滤器可调用函数获取天数的差异

参数
callable $callback

用于过滤的回调。

Cake\Chronos\ChronosDate|null $other optional

要从中进行差别的实例。

bool $absolute optional

获取差异的绝对值

int $options optional

DatePeriod 选项,{@see https://php.ac.cn/manual/en/class.dateperiod.php}

返回
int

diffInMonths() ¶ public

diffInMonths(Cake\Chronos\ChronosDate|null $other = null, bool $absolute = true): int

获取月数的差异

参数
Cake\Chronos\ChronosDate|null $other optional

要从中进行差别的实例。

bool $absolute optional

获取差异的绝对值

返回
int

diffInWeekdays() ¶ public

diffInWeekdays(Cake\Chronos\ChronosDate|null $other = null, bool $absolute = true, int $options = 0): int

获取工作日的差异

参数
Cake\Chronos\ChronosDate|null $other optional

要从中进行差别的实例。

bool $absolute optional

获取差异的绝对值

int $options optional

DatePeriod 选项,{@see https://php.ac.cn/manual/en/class.dateperiod.php}

返回
int

diffInWeekendDays() ¶ public

diffInWeekendDays(Cake\Chronos\ChronosDate|null $other = null, bool $absolute = true, int $options = 0): int

使用过滤器获取周末的差异

参数
Cake\Chronos\ChronosDate|null $other optional

要从中进行差别的实例。

bool $absolute optional

获取差异的绝对值

int $options optional

DatePeriod 选项,{@see https://php.ac.cn/manual/en/class.dateperiod.php}

返回
int

diffInWeeks() ¶ public

diffInWeeks(Cake\Chronos\ChronosDate|null $other = null, bool $absolute = true): int

获取周数的差异

参数
Cake\Chronos\ChronosDate|null $other optional

要从中进行差别的实例。

bool $absolute optional

获取差异的绝对值

返回
int

diffInYears() ¶ public

diffInYears(Cake\Chronos\ChronosDate|null $other = null, bool $absolute = true): int

获取年数的差异

参数
Cake\Chronos\ChronosDate|null $other optional

要从中进行差别的实例。

bool $absolute optional

获取差异的绝对值

返回
int

endOfCentury() ¶ public

endOfCentury(): static

将日期重置为世纪末,时间重置为 23:59:59

返回
static

endOfDecade() ¶ public

endOfDecade(): static

将日期重置为十年末

返回
static

endOfMonth() ¶ public

endOfMonth(): static

将日期重置为月底

返回
static

endOfWeek() ¶ public

endOfWeek(): static

将日期重置为周末(在 $weekEndsAt 中定义),时间重置为 23:59:59

返回
static

endOfYear() ¶ public

endOfYear(): static

将日期重置为年底

返回
static

equals() ¶ public

equals(Cake\Chronos\ChronosDate $other): bool

确定实例是否等于另一个实例

参数
Cake\Chronos\ChronosDate $other

要比较的实例。

返回
bool

farthest() ¶ public

farthest(Cake\Chronos\ChronosDate $first, Cake\Chronos\ChronosDate $second, Cake\Chronos\ChronosDate ...$others): self

获取距实例最远的日期。

参数
Cake\Chronos\ChronosDate $first

要比较的实例。

Cake\Chronos\ChronosDate $second

要比较的实例。

Cake\Chronos\ChronosDate ...$others

要比较的其他实例。

返回
self

firstOfMonth() ¶ public

firstOfMonth(int|null $dayOfWeek = null): static

修改为当前月份中给定一周的第一次出现。如果没有提供 dayOfWeek,则修改为当前月份的第一天。使用提供的常量来指示所需的 dayOfWeek,例如 Chronos::MONDAY。

参数
int|null $dayOfWeek 可选

要移动到的星期几。

返回
static

firstOfQuarter() ¶ public

firstOfQuarter(int|null $dayOfWeek = null): static

修改为当前季度中给定一周的第一次出现。如果没有提供 dayOfWeek,则修改为当前季度的第一天。使用提供的常量来指示所需的 dayOfWeek,例如 Chronos::MONDAY。

参数
int|null $dayOfWeek 可选

要移动到的星期几。

返回
static

firstOfYear() ¶ public

firstOfYear(int|null $dayOfWeek = null): static

修改为当前年份中给定一周的第一次出现。如果没有提供 dayOfWeek,则修改为当前年份的第一天。使用提供的常量来指示所需的 dayOfWeek,例如 Chronos::MONDAY。

参数
int|null $dayOfWeek 可选

要移动到的星期几。

返回
static

format() ¶ public

format(string $format): string

根据 DateTimeImmutable::format() 返回格式化的日期字符串。

参数
string $format

字符串格式

返回
string

getLastErrors() ¶ public static

getLastErrors(): array|false

返回上次调用 createFromFormat() 时的解析警告和错误。

返回与 DateTimeImmutable::getLastErrors() 相同的数据。

返回
array|false

greaterThan() ¶ public

greaterThan(Cake\Chronos\ChronosDate $other): bool

确定实例是否大于(在)另一个实例之后

参数
Cake\Chronos\ChronosDate $other

要比较的实例。

返回
bool

greaterThanOrEquals() ¶ public

greaterThanOrEquals(Cake\Chronos\ChronosDate $other): bool

确定实例是否大于(在)或等于另一个实例之后

参数
Cake\Chronos\ChronosDate $other

要比较的实例。

返回
bool

isFirstHalf() ¶ public

isFirstHalf(): bool

确定实例是否在一年上半年的范围内

返回
bool

isFriday() ¶ public

isFriday(): bool

检查这一天是否为星期五。

返回
bool

isFuture() ¶ public

isFuture(DateTimeZone|string|null $timezone = null): bool

确定实例是否在未来,即大于(在)现在之后

参数
DateTimeZone|string|null $timezone optional

用于当前时间的时区。

返回
bool

isLastMonth() ¶ public

isLastMonth(DateTimeZone|string|null $timezone = null): bool

确定实例是否在过去的一个月内

参数
DateTimeZone|string|null $timezone optional

用于当前时间的时区。

返回
bool

isLastWeek() ¶ public

isLastWeek(DateTimeZone|string|null $timezone = null): bool

确定实例是否在过去的一周内

参数
DateTimeZone|string|null $timezone optional

用于当前时间的时区。

返回
bool

isLastYear() ¶ public

isLastYear(DateTimeZone|string|null $timezone = null): bool

确定实例是否在过去的一年内

参数
DateTimeZone|string|null $timezone optional

用于当前时间的时区。

返回
bool

isLeapYear() ¶ public

isLeapYear(): bool

确定实例是否是闰年

返回
bool

isMonday() ¶ public

isMonday(): bool

检查这一天是否是星期一。

返回
bool

isNextMonth() ¶ public

isNextMonth(DateTimeZone|string|null $timezone = null): bool

确定实例是否在接下来的一个月内

参数
DateTimeZone|string|null $timezone optional

用于当前时间的时区。

返回
bool

isNextWeek() ¶ public

isNextWeek(DateTimeZone|string|null $timezone = null): bool

确定实例是否在接下来的一个星期内

参数
DateTimeZone|string|null $timezone optional

用于当前时间的时区。

返回
bool

isNextYear() ¶ public

isNextYear(DateTimeZone|string|null $timezone = null): bool

确定实例是否在接下来的一个年内

参数
DateTimeZone|string|null $timezone optional

用于当前时间的时区。

返回
bool

isPast() ¶ public

isPast(DateTimeZone|string|null $timezone = null): bool

确定实例是否在过去,即小于(早于)现在

参数
DateTimeZone|string|null $timezone optional

用于当前时间的时区。

返回
bool

isSaturday() ¶ public

isSaturday(): bool

检查这一天是否是星期六。

返回
bool

isSecondHalf() ¶ public

isSecondHalf(): bool

确定实例是否在今年的下半年

返回
bool

isSunday() ¶ public

isSunday(): bool

检查这一天是否是星期日。

返回
bool

isThursday() ¶ public

isThursday(): bool

检查这一天是否是星期四。

返回
bool

isToday() ¶ public

isToday(DateTimeZone|string|null $timezone = null): bool

确定实例是否为今天

参数
DateTimeZone|string|null $timezone optional

用于当前时间的时区。

返回
bool

isTomorrow() ¶ public

isTomorrow(DateTimeZone|string|null $timezone = null): bool

确定实例是否为明天

参数
DateTimeZone|string|null $timezone optional

用于当前时间的时区。

返回
bool

isTuesday() ¶ public

isTuesday(): bool

检查这一天是否是星期二。

返回
bool

isWednesday() ¶ public

isWednesday(): bool

检查这一天是否是星期三。

返回
bool

isWeekday() ¶ public

isWeekday(): bool

确定实例是否是工作日

返回
bool

isWeekend() ¶ public

isWeekend(): bool

确定实例是否是周末

返回
bool

isWithinNext() ¶ public

isWithinNext(string|int $timeInterval): bool

如果此实例将在指定的时间间隔内发生,则返回 true

参数
string|int $timeInterval

带空格的时间类型数值。有效类型的示例:6 hours, 2 days, 1 minute。

返回
bool

isYesterday() ¶ public

isYesterday(DateTimeZone|string|null $timezone = null): bool

确定实例是否为昨天

参数
DateTimeZone|string|null $timezone optional

用于当前时间的时区。

返回
bool

lastOfMonth() ¶ public

lastOfMonth(int|null $dayOfWeek = null): static

修改为当前月份中给定一周的最后一次出现。如果没有提供 dayOfWeek,则修改为当前月份的最后一天。使用提供的常量来指示所需 dayOfWeek,例如 Chronos::MONDAY。

参数
int|null $dayOfWeek 可选

要移动到的星期几。

返回
static

lastOfQuarter() ¶ public

lastOfQuarter(int|null $dayOfWeek = null): static

修改为当前季度中给定一周的最后一次出现。如果没有提供 dayOfWeek,则修改为当前季度的最后一天。使用提供的常量来指示所需 dayOfWeek,例如 Chronos::MONDAY。

参数
int|null $dayOfWeek 可选

要移动到的星期几。

返回
static

lastOfYear() ¶ public

lastOfYear(int|null $dayOfWeek = null): static

修改为当前年份中给定一周的最后一次出现。如果没有提供 dayOfWeek,则修改为当前年份的最后一天。使用提供的常量来指示所需 dayOfWeek,例如 Chronos::MONDAY。

参数
int|null $dayOfWeek 可选

要移动到的星期几。

返回
static

lessThan() ¶ public

lessThan(Cake\Chronos\ChronosDate $other): bool

确定实例是否小于(早于)另一个实例

参数
Cake\Chronos\ChronosDate $other

要比较的实例。

返回
bool

lessThanOrEquals() ¶ public

lessThanOrEquals(Cake\Chronos\ChronosDate $other): bool

确定实例是否小于(早于)或等于另一个实例

参数
Cake\Chronos\ChronosDate $other

要比较的实例。

返回
bool

modify() ¶ public

modify(string $modifier): static

根据 DateTimeImmutable::modifier() 创建一个新的实例,其中日期已修改。

尝试更改时间组件将引发异常

参数
string $modifier

日期修改器

返回
static

month() ¶ public

month(int $value): static

设置实例的月份

参数
int $value

月份值。

返回
static

next() ¶ public

next(int|null $dayOfWeek = null): static

修改为给定一周的下次出现。如果没有提供 dayOfWeek,则修改为当前一周的下次出现。使用提供的常量来指示所需 dayOfWeek,例如 Chronos::MONDAY。

参数
int|null $dayOfWeek 可选

要移动到的星期几。

返回
static

notEquals() ¶ public

notEquals(Cake\Chronos\ChronosDate $other): bool

确定实例是否不等于另一个实例

参数
Cake\Chronos\ChronosDate $other

要比较的实例。

返回
bool

now() ¶ public static

now(DateTimeZone|string|null $timezone = null): static

获取今天的日期。

参数
DateTimeZone|string|null $timezone optional

用于当前时间的时区。

返回
static

nthOfMonth() ¶ public

nthOfMonth(int $nth, int $dayOfWeek): static|false

修改为当前月份中给定一周的指定次出现。如果计算出的出现超出了当前月份的范围,则返回 false 并且不会进行任何修改。使用提供的常量来指示所需 dayOfWeek,例如 Chronos::MONDAY。

参数
int $nth

要使用的偏移量。

int $dayOfWeek

要移动到的星期几。

返回
static|false

nthOfQuarter() ¶ public

nthOfQuarter(int $nth, int $dayOfWeek): static|false

修改为当前季度中给定一周的指定次出现。如果计算出的出现超出了当前季度的范围,则返回 false 并且不会进行任何修改。使用提供的常量来指示所需 dayOfWeek,例如 Chronos::MONDAY。

参数
int $nth

要使用的偏移量。

int $dayOfWeek

要移动到的星期几。

返回
static|false

nthOfYear() ¶ public

nthOfYear(int $nth, int $dayOfWeek): static|false

修改为当前年份中给定一周的指定次出现。如果计算出的出现超出了当前年份的范围,则返回 false 并且不会进行任何修改。使用提供的常量来指示所需 dayOfWeek,例如 Chronos::MONDAY。

参数
int $nth

要使用的偏移量。

int $dayOfWeek

要移动到的星期几。

返回
static|false

parse() ¶ public static

parse(Cake\Chronos\ChronosDateDateTimeInterface|string $time): static

从字符串创建实例。这是构造函数的别名,它允许更好的流畅语法,因为它允许您执行 Chronos::parse('Monday next week')->fn() 而不是 (new Chronos('Monday next week'))->fn()

参数
Cake\Chronos\ChronosDateDateTimeInterface|string $time

要解析的与 strtotime 兼容的字符串。

返回
static

previous() ¶ public

previous(int|null $dayOfWeek = null): static

修改为给定一周的上次出现。如果没有提供 dayOfWeek,则修改为当前一周的上次出现。使用提供的常量来指示所需 dayOfWeek,例如 Chronos::MONDAY。

参数
int|null $dayOfWeek 可选

要移动到的星期几。

返回
static

resetToStringFormat() ¶ public static

resetToStringFormat(): void

将 __toString() 格式重置为 DEFAULT_TO_STRING_FORMAT。

返回
void

setDate() ¶ public

setDate(int $year, int $month, int $day): static

设置日期。

参数
int $year

要设置的年份。

int $month

要设置的月份。

int $day

要设置的日期。

返回
static

setISODate() ¶ public

setISODate(int $year, int $week, int $dayOfWeek = 1): static

根据 ISO 8601 标准设置日期

参数
int $year

日期的年份。

int $week

日期的星期数。

int $dayOfWeek optional

从一周的第一天开始的偏移量。

返回
static

setToStringFormat() ¶ public static

setToStringFormat(string $format): void

设置 __toString() 格式。

参数
string $format

参见 format() 以获取可接受的说明符。

返回
void

startOfCentury() ¶ public

startOfCentury(): static

将日期重置为世纪的第一天

返回
static

startOfDecade() ¶ public

startOfDecade(): static

将日期重置为十年的第一天

返回
static

startOfMonth() ¶ public

startOfMonth(): static

将日期重置为月份的第一天

返回
static

startOfWeek() ¶ public

startOfWeek(): static

将日期重置为一周的第一天(在 $weekStartsAt 中定义)

返回
static

startOfYear() ¶ public

startOfYear(): static

将日期重置为年份的第一天

返回
static

sub() ¶ public

sub(DateInterval $interval): static

从日期中减去间隔。

对时间的任何更改将被忽略并重置为 00:00:00

参数
DateInterval $interval

要修改此日期的间隔。

返回
static

subDays() ¶ public

subDays(int $value): static

从实例中删除天数

参数
int $value

要减去的日期数。

返回
static

subMonths() ¶ public

subMonths(int $value): static

从实例中删除月份

与 addMonths() 的行为相同。

参数
int $value

要减去的月份数。

返回
static

subMonthsWithOverflow() ¶ public

subMonthsWithOverflow(int $value): static

将带有溢出的月数添加到实例中。正 $value 向前移动,而负 $value 向后移动。

如果新的ChronosDate不存在,则天数溢出到下一个月。

示例

 (new Chronos('2012-01-30'))->addMonthsWithOverflow(1); // Results in 2013-03-01
参数
int $value

要减去的月份数。

返回
static

subWeekdays() ¶ public

subWeekdays(int $value): static

从实例中删除工作日

参数
int $value

要减去的星期数。

返回
static

subWeeks() ¶ public

subWeeks(int $value): static

从实例中删除星期

参数
int $value

要减去的星期数。

返回
static

subYears() ¶ public

subYears(int $value): static

从实例中删除年份。

与 addYears() 的行为相同。

参数
int $value

要减去的年份数。

返回
static

subYearsWithOverflow() ¶ public

subYearsWithOverflow(int $value): static

从实例中删除带有溢出的年份

与 addYeasrWithOverflow() 的行为相同。

参数
int $value

要减去的年份数。

返回
static

toAtomString() ¶ public

toAtomString(): string

将实例格式化为 ATOM

返回
string

toCookieString() ¶ public

toCookieString(): string

将实例格式化为 COOKIE

返回
string

toDateString() ¶ public

toDateString(): string

将实例格式化为日期

返回
string

toDateTimeImmutable() ¶ public

toDateTimeImmutable(DateTimeZone|string|null $timezone = null): DateTimeImmutable

以午夜的 DateTimeImmutable 实例形式返回日期。

参数
DateTimeZone|string|null $timezone optional

DateTimeImmutable 实例所在的时区。

返回
DateTimeImmutable

toDateTimeString() ¶ public

toDateTimeString(): string

将实例格式化为日期和时间

返回
string

toDayDateTimeString() ¶ public

toDayDateTimeString(): string

使用星期、日期和时间格式化实例

返回
string

toFormattedDateString() ¶ public

toFormattedDateString(): string

将实例格式化为可读日期

返回
string

toIso8601String() ¶ public

toIso8601String(): string

将实例格式化为 ISO8601

返回
string

toNative() ¶ public

toNative(DateTimeZone|string|null $timezone = null): DateTimeImmutable

以午夜的 DateTimeImmutable 实例形式返回日期。

toDateTimeImmutable() 的别名。

参数
DateTimeZone|string|null $timezone optional

DateTimeImmutable 实例所在的时区。

返回
DateTimeImmutable

toQuarter() ¶ public

toQuarter(bool $range = false): array|int

返回季度

参数
bool $range optional

范围。

返回
array|int

toRfc1036String() ¶ public

toRfc1036String(): string

将实例格式化为 RFC1036

返回
string
链接
https://tools.ietf.org/html/rfc1036

toRfc1123String() ¶ public

toRfc1123String(): string

将实例格式化为 RFC1123

返回
string
链接
https://tools.ietf.org/html/rfc1123

toRfc2822String() ¶ public

toRfc2822String(): string

将实例格式化为 RFC2822

返回
string
链接
https://tools.ietf.org/html/rfc2822

toRfc3339String() ¶ public

toRfc3339String(): string

将实例格式化为 RFC3339

返回
string
链接
https://tools.ietf.org/html/rfc3339

toRfc822String() ¶ public

toRfc822String(): string

将实例格式化为 RFC822

返回
string
链接
https://tools.ietf.org/html/rfc822

toRfc850String() ¶ public

toRfc850String(): string

将实例格式化为 RFC850

返回
string
链接
https://tools.ietf.org/html/rfc850

toRssString() ¶ public

toRssString(): string

将实例格式化为 RSS

返回
string

toTimeString() ¶ public

toTimeString(): string

将实例格式化为时间

返回
string

toUnixString() ¶ public

toUnixString(): string

返回一个 UNIX 时间戳。

返回
string

toW3cString() ¶ public

toW3cString(): string

将实例格式化为 W3C

返回
string

toWeek() ¶ public

toWeek(): int

返回 ISO 8601 年份的周数,星期一为一周的开始

返回
int

today() ¶ public static

today(DateTimeZone|string|null $timezone = null): static

获取今天的日期。

参数
DateTimeZone|string|null $timezone optional

用于 today 的时区。

返回
static

tomorrow() ¶ public static

tomorrow(DateTimeZone|string|null $timezone = null): static

获取明天的日期。

参数
DateTimeZone|string|null $timezone optional

用于 tomorrow 的时区。

返回
static

wasWithinLast() ¶ public

wasWithinLast(string|int $timeInterval): bool

如果此实例发生在指定的时间间隔内,则返回 true

参数
string|int $timeInterval

带空格的时间类型数值。有效类型的示例:6 hours, 2 days, 1 minute。

返回
bool

year() ¶ public

year(int $value): static

设置实例的年份。

参数
int $value

年份值。

返回
static

yesterday() ¶ public static

yesterday(DateTimeZone|string|null $timezone = null): static

获取昨天的日期。

参数
DateTimeZone|string|null $timezone optional

用于 yesterday 的时区。

返回
static

属性详情

$age ¶ public @property-read

使用默认参数执行 diffInYears()。

类型
int

$day ¶ public @property-read

类型
int<1, 31>

$dayOfWeek ¶ public @property-read

1(星期一)到 7(星期日)

类型
int<1, 7>

$dayOfYear ¶ public @property-read

0 到 365

类型
int<0, 365>

$days ¶ protected static

一周中每一天的名称。

类型
array

$daysInMonth ¶ public @property-read

给定月份的天数

类型
int<1, 31>

$diffFormatter ¶ protected static

差异格式化对象的实例。

类型
Cake\Chronos\DifferenceFormatterInterface|null

$half ¶ public @property-read

一年的前半部分,1 表示 1 月到 6 月,2 表示 7 月到 12 月。

类型
int<1, 2>

$lastErrors ¶ protected static

上次调用 createFromFormat() 时的错误。

类型
array|false

$month ¶ public @property-read

类型
int<1, 12>

$native ¶ protected

类型
DateTimeImmutable

$quarter ¶ public @property-read

此实例的季度,1 - 4

类型
int<1, 4>

$toStringFormat ¶ protected static

类型转换时,用于 __toString 方法的格式。

类型
string

$weekOfMonth ¶ public @property-read

1 到 5

类型
int<1, 5>

$weekOfYear ¶ public @property-read

ISO-8601 年的周数,周从星期一开始

类型
int<1, 53>

$year ¶ public @property-read

类型
int

$yearIso ¶ public @property-read

类型
int
OpenHub
Pingping
Linode
  • 商业解决方案
  • 展示
  • 文档
  • 书籍
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 标识与商标
  • 社区
  • 参与进来
  • 问题 (Github)
  • 面包店
  • 特色资源
  • 培训
  • 聚会
  • 我的 CakePHP
  • CakeFest
  • 通讯
  • 领英
  • YouTube
  • 脸书
  • 推特
  • Mastodon
  • 帮助与支持
  • 论坛
  • Stack Overflow
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API 文档 生成