CakePHP
  • 文档
    • 书籍
    • API
    • 视频
    • 报告安全问题
    • 隐私政策
    • 标识和商标
  • 商业解决方案
  • 礼品
  • 公路旅行
  • 团队
  • 社区
    • 社区
    • 参与
    • 问题(Github)
    • Bakery
    • 精选资源
    • 培训
    • 聚会
    • 我的 CakePHP
    • CakeFest
    • 时事通讯
    • LinkedIn
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • 帮助与支持
    • 论坛
    • Stack Overflow
    • IRC
    • Slack
    • 付费支持
CakePHP

C CakePHP 5.1 Chiffon API

  • 项目
    • CakePHP
      • CakePHP
      • Chronos
      • Elastic Search
      • 队列
  • 版本
    • 5.1
      • 5.1
      • 5.0
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

命名空间

  • 全局
  • Cake
    • 缓存
    • 集合
    • 命令
    • 控制台
    • 控制器
    • 核心
    • 数据库
    • 数据源
    • 错误
    • 事件
    • 表单
    • Http
    • 国际化
      • 异常
      • 格式化程序
      • 中间件
      • 解析器
    • 日志
    • 邮件发送器
    • 网络
    • ORM
    • 路由
    • 测试套件
    • 实用工具
    • 验证
    • 视图

类日期

扩展 Chronos 提供的 Date 类。

添加了方便的方法和区域感知格式化辅助函数。

命名空间: Cake\I18n

常量

  • 字符串
    DEFAULT_TO_STRING_FORMAT ¶
    'Y-m-d'

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

属性摘要

  • $_jsonEncodeFormat protected static
    Closure|string|int

    将此对象转换为 JSON 时使用的格式。

  • $_toStringFormat protected static
    string|int

    使用 Cake\I18n\Date::i18nFormat() 和 __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

    差异格式化对象的实例。

  • $formatters protected static
    array<string,IntlDateFormatter>

    日期格式化程序的内存缓存

  • $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
  • $niceFormat public static
    string|int

    使用 Cake\I18n\Date::nice() 格式化时间时使用的格式

  • $quarter public @property-read
    int<1, 4>

    此实例所在的季度,1 到 4

  • $toStringFormat protected static
    字符串

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

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

    1 到 5

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

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

  • $wordAccuracy public static
    array<string, string>

    使用 Date::timeAgoInWords() 格式化时间且差异小于 Date::$wordEnd 时使用的格式

  • $wordEnd public static
    字符串

    相对时间提示的结束时间

  • $wordFormat public static
    string|int

    使用 Cake\I18n\Date::timeAgoInWords() 格式化时间且差异大于 Cake\I18n\Date::$wordEnd 时使用的格式

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

方法摘要

  • __construct() public

    创建一个新的 Immutable Date 实例。

  • __debugInfo() public

    返回用于调试的属性。

  • __get() public

    获取对象的一部分

  • __isset() public

    检查对象上是否存在属性

  • __toString() public

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

  • _formatObject() protected

    返回翻译并本地化的日期字符串。实现 PHP 5.5+ 中的 IntlDateFormatter::formatObject()。

  • _parseDateTime() protected static

    根据传递的或配置的日期时间格式,解析提供的时

  • 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

    确定实例是否大于(晚于)或等于另一个实例

  • i18nFormat() 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

    确定实例是否为昨天

  • jsonSerialize() public

    返回将此对象转换为 JSON 时应序列化的字符串

  • 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。

  • nice() public

    返回此对象的格式良好的日期字符串。

  • 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()

  • parseDate() public static

    根据传递的或配置的格式解析提供的 $date 字符串后,返回一个新的 Date 对象。此方法依赖于区域设置,传递给此函数的任何字符串都将被解释为依赖于区域设置的字符串。

  • previous() public

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

  • resetToStringFormat() public static

    将 __toString() 格式重置为 DEFAULT_TO_STRING_FORMAT。

  • setDate() public

    设置日期。

  • setISODate() public

    根据 ISO 8601 标准设置日期

  • setJsonEncodeFormat() public static

    设置将此对象转换为 JSON 时使用的默认格式

  • setToStringFormat() public static

    设置将此类型实例类型转换为字符串时使用的默认格式

  • 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

    从实例中删除带溢出的年数

  • timeAgoInWords() 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)

创建一个新的 Immutable Date 实例。

日期没有时间或时区组件。在内部,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 格式指定的格式化字符串。

返回
字符串

_formatObject() ¶ protected

_formatObject(DateTimeInterface $date, array<int>|string $format, string|null $locale): string

返回翻译并本地化的日期字符串。实现 PHP 5.5+ 中的 IntlDateFormatter::formatObject()。

参数
DateTimeInterface $date

日期。

array<int>|string $format

格式。

string|null $locale

应该显示日期的区域设置名称。

返回
字符串

_parseDateTime() ¶ protected static

_parseDateTime(string $time, array<int>|string $format, DateTimeZone|string|null $tz = null): static|null

根据传递的或配置的日期时间格式,解析提供的时

与 DateTime 不同,返回的实例的时区始终转换为 $tz(如果为空则为默认时区),即使 $time 字符串指定了时区。这是 IntlDateFormatter 的限制。

如果无法解析提供的日期,则将返回 null。

示例

 $time = Time::parseDateTime('10/13/2013 12:54am');
 $time = Time::parseDateTime('13 Oct, 2013 13:54', 'dd MMM, y H:mm');
 $time = Time::parseDateTime('10/10/2015', [IntlDateFormatter::SHORT, IntlDateFormatter::NONE]);
参数
string $time

要解析的时间字符串。

array<int>|string $format

IntlDateFormatter 接受的任何格式。

DateTimeZone|string|null $tz optional

实例的时区

返回
static|null

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 等

返回
字符串

diffFormatter() ¶ public static

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

获取差异格式化程序实例。

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

差异格式化程序

返回
Cake\I18n\RelativeTimeFormatter

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 optional

要移动到的星期几。

返回
static

firstOfQuarter() ¶ public

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

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

参数
int|null $dayOfWeek optional

要移动到的星期几。

返回
static

firstOfYear() ¶ public

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

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

参数
int|null $dayOfWeek optional

要移动到的星期几。

返回
static

format() ¶ public

format(string $format): string

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

参数
string $format

String format

返回
字符串

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

i18nFormat() ¶ public

i18nFormat(string|int|null $format = null, string|null $locale = null): string|int

使用指定区域设置的优选格式和语言返回此时间对象的格式化字符串。

可以指定要显示的字符串的所需格式。您可以将 IntlDateFormatter 常量作为此函数的第一个参数传递,或者传递以下资源中指定的完整 ICU 日期格式字符串: https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax.

示例

$date = new Date('2014-04-20');
$date->i18nFormat(); // outputs '4/20/14' for the en-US locale
$date->i18nFormat(\IntlDateFormatter::FULL); // Use the full date format
$date->i18nFormat('yyyy-MM-dd'); // outputs '2014-04-20'

您可以通过 Date::setToStringFormat() 控制使用的默认格式。

您可以在 https://secure.php.net/manual/en/class.intldateformatter.php 了解可用的 IntlDateFormatter 常量。

如果您需要使用不同的区域设置来显示此时间对象,请将区域设置字符串作为此函数的第三个参数传递。

示例

$date = new Date('2014-04-20');
$time->i18nFormat(null, 'de-DE');
$time->i18nFormat(\IntlDateFormatter::FULL, 'de-DE');

您可以通过 Date::setDefaultLocale() 控制使用的默认区域设置。如果为空,则将从 intl.default_locale ini 配置中获取默认值。

参数
string|int|null $format optional

格式字符串。

string|null $locale optional

应以其显示日期的区域设置名称(例如 pt-BR)。

返回
string|int

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 小时、2 天、1 分钟。

返回
bool

isYesterday() ¶ public

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

确定实例是否为昨天

参数
DateTimeZone|string|null $timezone optional

用于现在的时区。

返回
bool

jsonSerialize() ¶ public

jsonSerialize(): string|int

返回将此对象转换为 JSON 时应序列化的字符串

返回
string|int

lastOfMonth() ¶ public

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

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

参数
int|null $dayOfWeek optional

要移动到的星期几。

返回
static

lastOfQuarter() ¶ public

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

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

参数
int|null $dayOfWeek optional

要移动到的星期几。

返回
static

lastOfYear() ¶ public

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

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

参数
int|null $dayOfWeek optional

要移动到的星期几。

返回
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 optional

要移动到的星期几。

返回
static

nice() ¶ public

nice(string|null $locale = null): string

返回此对象的格式良好的日期字符串。

要使用的格式存储在静态属性 Date::$niceFormat 中。

参数
string|null $locale optional

应以其显示日期的区域设置名称(例如 pt-BR)。

返回
字符串

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

parseDate() ¶ public static

parseDate(string $date, string|int|null $format = null): static|null

根据传递的或配置的格式解析提供的 $date 字符串后,返回一个新的 Date 对象。此方法依赖于区域设置,传递给此函数的任何字符串都将被解释为依赖于区域设置的字符串。

如果没有提供 $format,则将使用 wordFormat 格式。

如果无法解析提供的日期,则将返回 null。

示例

 $time = Date::parseDate('10/13/2013');
 $time = Date::parseDate('13 Oct, 2013', 'dd MMM, y');
 $time = Date::parseDate('13 Oct, 2013', IntlDateFormatter::SHORT);
参数
string $date

要解析的日期字符串。

string|int|null $format optional

IntlDateFormatter 接受的任何格式。

返回
static|null

previous() ¶ public

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

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

参数
int|null $dayOfWeek optional

要移动到的星期几。

返回
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

setJsonEncodeFormat() ¶ public static

setJsonEncodeFormat(Closure|string|int $format): void

设置将此对象转换为 JSON 时使用的默认格式

格式应为 IntlDateFormatter 中的格式常量(如 https://secure.php.net/manual/en/class.intldateformatter.php 中所述)或 http://www.icu-project.org/apiref/icu4c/classSimpleDateFormat.html#details 中指定的模式。

或者,格式可以提供回调函数。在这种情况下,回调函数可以接收此对象并返回格式化的字符串。

参数
Closure|string|int $format

格式。

返回
void
另请参见
\Cake\I18n\Date::i18nFormat()

setToStringFormat() ¶ public static

setToStringFormat(string|int $format): void

设置将此类型实例类型转换为字符串时使用的默认格式

格式应为 IntlDateFormatter 中的格式常量(如 https://secure.php.net/manual/en/class.intldateformatter.php 中所述)或 https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classSimpleDateFormat.html#details 中指定的模式。

参数
string|int $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

timeAgoInWords() ¶ public

timeAgoInWords(array<string, mixed> $options = []): string

根据当前日期和此对象之间的差异返回相对日期或格式化的绝对日期。

选项

  • from => 另一个 Date 对象,表示“现在”日期
  • format => 如果相对时间超过 end 指定的时长,则使用回退格式
  • accuracy => 指定日期描述的准确性(数组)
    • year => 如果年数 > 0,则使用此格式(默认“day”)
    • month => 如果月数 > 0,则使用此格式(默认“day”)
    • week => 如果周数 > 0,则使用此格式(默认“day”)
    • day => 如果周数 > 0,则使用此格式(默认“day”)
  • end => 相对日期说明的结束
  • relativeString => 输出相对日期时使用的 printf 兼容字符串
  • absoluteString => 输出绝对日期时使用的 printf 兼容字符串
  • timezone => 时间戳应以其格式化的用户时区。

相对日期看起来像这样

  • 3 周前,4 天前
  • 1 天前

默认日期格式为 d/M/YY,例如:09 年 2 月 18 日。格式化在内部使用 i18nFormat 进行,有关有效格式化字符串,请参阅该方法。

返回的字符串包含“ago”或“on”,并假定您会在函数输出之前正确添加诸如“Posted”之类的词语。

注意:如果差异为一周或更长时间,则最低级别的准确性为 day。

参数
array<string, mixed> $options 可选

选项数组。

返回
字符串

toAtomString() ¶ public

toAtomString(): string

将实例格式化为 ATOM

返回
字符串

toCookieString() ¶ public

toCookieString(): string

将实例格式化为 COOKIE

返回
字符串

toDateString() ¶ public

toDateString(): string

将实例格式化为日期

返回
字符串

toDateTimeImmutable() ¶ public

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

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

参数
DateTimeZone|string|null $timezone optional

DateTimeImmutable 实例所在的时区

返回
DateTimeImmutable

toDateTimeString() ¶ public

toDateTimeString(): string

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

返回
字符串

toDayDateTimeString() ¶ public

toDayDateTimeString(): string

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

返回
字符串

toFormattedDateString() ¶ public

toFormattedDateString(): string

将实例格式化为可读的日期。

返回
字符串

toIso8601String() ¶ public

toIso8601String(): string

将实例格式化为 ISO8601。

返回
字符串

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 可选

范围。

返回
array|int

toRfc1036String() ¶ public

toRfc1036String(): string

将实例格式化为 RFC1036。

返回
字符串
链接
https://tools.ietf.org/html/rfc1036

toRfc1123String() ¶ public

toRfc1123String(): string

将实例格式化为 RFC1123。

返回
字符串
链接
https://tools.ietf.org/html/rfc1123

toRfc2822String() ¶ public

toRfc2822String(): string

将实例格式化为 RFC2822。

返回
字符串
链接
https://tools.ietf.org/html/rfc2822

toRfc3339String() ¶ public

toRfc3339String(): string

将实例格式化为 RFC3339。

返回
字符串
链接
https://tools.ietf.org/html/rfc3339

toRfc822String() ¶ public

toRfc822String(): string

将实例格式化为 RFC822。

返回
字符串
链接
https://tools.ietf.org/html/rfc822

toRfc850String() ¶ public

toRfc850String(): string

将实例格式化为 RFC850。

返回
字符串
链接
https://tools.ietf.org/html/rfc850

toRssString() ¶ public

toRssString(): string

将实例格式化为 RSS。

返回
字符串

toTimeString() ¶ public

toTimeString(): string

将实例格式化为时间。

返回
字符串

toUnixString() ¶ public

toUnixString(): string

返回 UNIX 时间戳。

返回
字符串

toW3cString() ¶ public

toW3cString(): string

将实例格式化为 W3C。

返回
字符串

toWeek() ¶ public

toWeek(): int

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

返回
int

today() ¶ public static

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

获取今天的日期。

参数
DateTimeZone|string|null $timezone optional

用于今天的时区。

返回
static

tomorrow() ¶ public static

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

获取明天的日期。

参数
DateTimeZone|string|null $timezone optional

用于明天的时区。

返回
static

wasWithinLast() ¶ public

wasWithinLast(string|int $timeInterval): bool

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

参数
string|int $timeInterval

带有空格和时间类型的数值。有效类型的示例:6 小时、2 天、1 分钟。

返回
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

用于昨天的时区。

返回
static

属性详细

$_jsonEncodeFormat ¶ protected static

将此对象转换为 JSON 时使用的格式。

格式应为 IntlDateFormatter 中的格式常量(如 https://secure.php.net/manual/en/class.intldateformatter.php 中所述)或 https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classSimpleDateFormat.html#details 中指定的模式。

类型
Closure|string|int

$_toStringFormat ¶ protected static

使用 Cake\I18n\Date::i18nFormat() 和 __toString 格式化时间时使用的格式。

格式应为 IntlDateFormatter 中的格式常量(如 https://secure.php.net/manual/en/class.intldateformatter.php 中所述)或 https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classSimpleDateFormat.html#details 中指定的模式。

类型
string|int

$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

$formatters ¶ protected static

日期格式化程序的内存缓存

类型
array<string,IntlDateFormatter>

$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

$niceFormat ¶ public static

使用 Cake\I18n\Date::nice() 格式化时间时使用的格式

格式应为 IntlDateFormatter 中的格式常量(如 https://secure.php.net/manual/en/class.intldateformatter.php 中所述)或 https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classSimpleDateFormat.html#details 中指定的模式。

类型
string|int

$quarter ¶ public @property-read

此实例所在的季度,1 到 4

类型
int<1, 4>

$toStringFormat ¶ protected static

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

类型
字符串

$weekOfMonth ¶ public @property-read

1 到 5

类型
int<1, 5>

$weekOfYear ¶ public @property-read

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

类型
int<1, 53>

$wordAccuracy ¶ public static

使用 Date::timeAgoInWords() 格式化时间且差异小于 Date::$wordEnd 时使用的格式

类型
array<string, string>

$wordEnd ¶ public static

相对时间提示的结束时间

类型
字符串

$wordFormat ¶ public static

使用 Cake\I18n\Date::timeAgoInWords() 格式化时间且差异大于 Cake\I18n\Date::$wordEnd 时使用的格式

类型
string|int

$year ¶ public @property-read

类型
int

$yearIso ¶ public @property-read

类型
int
OpenHub
Pingping
Linode
  • 企业解决方案
  • 展示
  • 文档
  • 书籍
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 标识和商标
  • 社区
  • 参与
  • 问题(Github)
  • Bakery
  • 精选资源
  • 培训
  • 聚会
  • 我的 CakePHP
  • CakeFest
  • 时事通讯
  • LinkedIn
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • 帮助与支持
  • 论坛
  • Stack Overflow
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API 文档 生成