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
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
      • Exception
      • Formatter
      • Middleware
      • Parser
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

DateTime 类

扩展内置 DateTime 类,提供便捷方法和本地化格式化辅助函数。

命名空间: Cake\I18n

常量

  • int
    DAYS_PER_WEEK ¶
    7
  • string
    DEFAULT_TO_STRING_FORMAT ¶
    'Y-m-d H:i:s'

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

  • int
    FRIDAY ¶
    5
  • int
    HOURS_PER_DAY ¶
    24
  • int
    MINUTES_PER_HOUR ¶
    60
  • int
    MONDAY ¶
    1
  • int
    MONTHS_PER_QUARTER ¶
    3
  • int
    MONTHS_PER_YEAR ¶
    12
  • int
    SATURDAY ¶
    6
  • int
    SECONDS_PER_MINUTE ¶
    60
  • int
    SUNDAY ¶
    7
  • int
    THURSDAY ¶
    4
  • int
    TUESDAY ¶
    2
  • string
    UNIX_TIMESTAMP_FORMAT ¶
    'unixTimestampFormat'

    将值序列化为 Unix 时间戳。

  • int
    WEDNESDAY ¶
    3
  • int
    WEEKS_PER_YEAR ¶
    52
  • int
    YEARS_PER_CENTURY ¶
    100
  • int
    YEARS_PER_DECADE ¶
    10

属性概要

  • $_jsonEncodeFormat protected static
    Closure|array<int>|string|int

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

  • $_toStringFormat protected static
    array<int>|string|int

    使用 Cake\I18n\DateTime::i18nFormat() 和 __toString 格式化时间时要使用的格式。此格式也由 parseDateTime() 使用。

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

    给定月份的天数。

  • $defaultLocale protected static
    string|null

    用于显示格式化日期字符串的默认语言环境。

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

    差异格式化对象的实例。

  • $dst public @property-read
    bool

    夏令时指示器,如果为夏令时,则为 true,否则为 false。

  • $formatters protected static
    array<string,IntlDateFormatter>

    日期格式化器的内存缓存。

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

    一年的前半段,1 代表 1 月到 6 月,2 代表 7 月到 12 月。

  • $hour public @property-read
    int<0, 23>
  • $lastErrors protected static
    array|false

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

  • $lenientParsing protected static
    bool

    是否为 IntlDateFormatter 启用宽松解析。

  • $local public @property-read
    bool

    检查时区是否为本地时区,如果为本地时区,则为 true,否则为 false。

  • $micro public @property-read
    int<0, 999999>
  • $microsecond public @property-read
    int<0, 999999>
  • $minute public @property-read
    int<0, 59>
  • $month public @property-read
    int<1, 12>
  • $niceFormat public static
    array<int>|string|int

    使用 Cake\I18n\DateTime::nice() 格式化时间时要使用的格式。

  • $offset public @property-read
    int

    UTC 的时区偏移量(以秒为单位)。

  • $offsetHours public @property-read
    int

    UTC 的时区偏移量(以小时为单位)。

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

    此实例的季度,从 1 到 4。

  • $relativePattern protected static
    string

    相对时期的正则表达式。

  • $second public @property-read
    int<0, 59>
  • $testNow protected static
    Cake\Chronos\Chronos|null

    创建 now 实例时要返回的测试 Chronos 实例。

  • $timestamp public @property-read
    int

    自 Unix 纪元以来的秒数。

  • $timezone public @property-read
    DateTimeZone

    当前时区。

  • $timezoneName public @property-read
    string
  • $toStringFormat protected static
    string

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

  • $tz public @property-read
    DateTimeZone

    时区的别名。

  • $tzName public @property-read
    string
  • $utc public @property-read
    bool

    检查时区是否为 UTC,如果为 UTC,则为 true,否则为 false。

  • $weekEndsAt protected static
    int

    一周的最后一天。

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

    从 1 到 5。

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

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

  • $weekStartsAt protected static
    int

    一周的第一天

  • $weekendDays protected static
    array

    周末的日子

  • $wordAccuracy public static
    array<string, string>

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

  • $wordEnd public static
    string

    相对时间描述的结束时间

  • $wordFormat public static
    array<int>|string|int

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

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

方法摘要

  • __construct() public

    创建一个新的 Chronos 实例。

  • __debugInfo() public

    返回用于调试的属性。

  • __get() public

    获取对象的一部分

  • __isset() public

    检查对象上是否存在属性

  • __toString() public

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

  • _formatObject() protected

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

  • _parseDateTime() protected static

    解析传递的或配置的日期时间格式的提供的字符串后,返回一个新的 Time 对象。此方法依赖于区域设置。传递给此函数的任何字符串将被解释为依赖于区域设置的字符串。

  • addDays() public

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

  • addHours() public

    在实例中添加小时数。正 $value 向前移动,负 $value 向后移动。

  • addMinutes() public

    在实例中添加分钟数。正 $value 向前移动,负 $value 向后移动。

  • addMonths() public

    在实例中添加月份。正 $value 向前移动,负 $value 向后移动。

  • addMonthsWithOverflow() public

    在实例中添加带溢出的月份。正 $value 向前移动,负 $value 向后移动。

  • addSeconds() public

    在实例中添加秒数。正 $value 向前移动,负 $value 向后移动。

  • addWeekdays() public

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

  • addWeeks() public

    在实例中添加星期。正 $value 向前移动,负 $value 向后移动。

  • addYears() public

    在实例中添加年份。正 $value 向前移动,负 $value 向后移动。

  • addYearsWithOverflow() public

    在实例中添加带溢出的年份。正 $value 向前移动,负 $value 向后移动。

  • average() public

    将当前实例修改为给定实例(默认现在)和当前实例的平均值。

  • between() public

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

  • closest() public

    获取与实例最接近的日期。

  • create() public static

    从特定的日期和时间创建一个实例。

  • createFromArray() public static

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

  • createFromDate() public static

    仅从日期创建一个实例。时间部分设置为现在。

  • createFromFormat() public static

    从特定格式创建一个实例

  • createFromTime() public static

    仅从时间创建一个实例。日期部分设置为今天。

  • createFromTimestamp() public static

    从时间戳创建一个实例

  • createInterval() public static

    从指定的 value 创建一个新的 DateInterval 实例。

  • day() public

    设置实例的天数

  • diff() public

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

  • diffFiltered() public

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

  • diffForHumans() public

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

  • diffFormatter() public static

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

  • diffInDays() public

    获取天数的差异

  • diffInDaysFiltered() public

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

  • diffInHours() public

    获取小时数的差异

  • diffInHoursFiltered() public

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

  • diffInMinutes() public

    获取分钟数的差异

  • diffInMonths() public

    获取月份的差异

  • diffInMonthsIgnoreTimezone() public

    忽略时区获取月份的差异。这意味着月份是在指定时区中计算的,没有先转换为 UTC。这将防止日期更改,这可能会更改月份。

  • diffInSeconds() public

    获取秒数的差异

  • diffInWeekdays() public

    获取工作日的差异

  • diffInWeekendDays() public

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

  • diffInWeeks() public

    获取星期数的差异

  • diffInYears() public

    获取年份的差异

  • disableLenientParsing() public static

    为区域设置格式启用宽松解析。

  • enableLenientParsing() public static

    为区域设置格式启用宽松解析。

  • endOfCentury() public

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

  • endOfDay() public

    将时间设置为 23:59:59 或 23:59:59.999999,如果 $microseconds 为真。

  • endOfDecade() public

    将日期设置为十年末,时间设置为 23:59:59

  • endOfMonth() public

    将日期设置为月底,时间设置为 23:59:59

  • endOfWeek() public

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

  • endOfYear() public

    将日期设置为年末,时间设置为 23:59:59

  • 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() 返回格式化的日期字符串。

  • fromNow() public static

    获取给定时间剩余时间的便捷方法。

  • getDefaultLocale() public static

    获取默认区域设置。

  • getLastErrors() public static

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

  • getOffset() public

    返回时区偏移量。

  • getTestNow() public static

    获取创建“现在”实例时要返回的 Chronos 实例(真实或模拟)。

  • getTimestamp() public

    获取此实例的 Unix 时间戳。

  • getTimezone() public

    返回为此实例设置的时区。

  • getWeekEndsAt() public static

    获取一周的最后一天

  • getWeekStartsAt() public static

    获取一周的第一天

  • getWeekendDays() public static

    获取周末

  • greaterThan() public

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

  • greaterThanOrEquals() public

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

  • hasRelativeKeywords() public static

    确定时间字符串中是否包含相对关键字,用于创建相对于现在的日期以供测试实例使用。例如:下周二

  • hasTestNow() public static

    确定是否设置了有效的测试实例。有效的测试实例是任何非空值。

  • hour() public

    设置实例的小时数

  • i18nFormat() public

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

  • instance() public static

    从 DateTimeInterface 创建一个实例

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

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

  • isSameDay() public

    检查传入的日期是否与实例的当前日期相同。

  • isSameMonth() public

    返回传入的日期是否与实例的月份和年份相同。

  • isSameYear() public

    返回传入的日期是否与实例的年份相同。

  • isSaturday() public

    检查这天是否为星期六。

  • isSecondHalf() public

    确定实例是否在后半年时间范围内。

  • isSunday() public

    检查这天是否为星期日。

  • isThisMonth() public

    如果此对象表示当前月内的日期,则返回 true。

  • isThisWeek() public

    如果此对象表示当前周内的日期,则返回 true。

  • isThisYear() public

    如果此对象表示当前年内的日期,则返回 true。

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

  • lenientParsingEnabled() public static

    获取区域设置格式解析是否设置为宽松。

  • lessThan() public

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

  • lessThanOrEquals() public

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

  • listTimezones() public static

    获取时区标识符列表。

  • max() public

    获取给定实例(默认值为现在)和当前实例之间的最大实例。

  • maxValue() public static

    为最大的支持日期创建一个实例。

  • microsecond() public

    设置实例的微秒。

  • min() public

    获取给定实例(默认值为现在)和当前实例之间的最小实例。

  • minValue() public static

    为最小的支持日期创建一个实例。

  • minute() 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('下周星期一')->fn() 而不是 (new Chronos('下周星期一'))->fn()

  • parseDate() public static

    根据传递或配置的日期时间格式,解析提供的 $date 字符串后,返回一个新的 Time 对象。此方法与区域设置相关,传递给此函数的任何字符串都将被解释为与区域设置相关的字符串。

  • parseDateTime() public static

    解析传递的或配置的日期时间格式的提供的字符串后,返回一个新的 Time 对象。此方法依赖于区域设置。传递给此函数的任何字符串将被解释为依赖于区域设置的字符串。

  • parseTime() public static

    根据传递或配置的日期时间格式,解析提供的 $time 字符串后,返回一个新的 Time 对象。此方法与区域设置相关,传递给此函数的任何字符串都将被解释为与区域设置相关的字符串。

  • previous() public

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

  • resetToStringFormat() public static

    将用于将此类型的实例转换为字符串的格式重置为默认值。

  • rolloverTime() protected static

    更新值为剩余值,并返回时间单位的翻转值,如果未翻转,则返回 null。

  • safeCreateDateTimeZone() protected static

    从字符串或 DateTimeZone 创建 DateTimeZone。

  • second() public

    设置实例的秒。

  • secondsSinceMidnight() public

    从午夜开始的秒数。

  • secondsUntilEndOfDay() public

    到 23:59:59 的秒数。

  • setDate() public

    设置日期。

  • setDateTime() public

    设置日期和时间。

  • setDefaultLocale() public static

    设置默认区域设置。

  • setISODate() public

    根据 ISO 8601 标准设置日期。

  • setJsonEncodeFormat() public static

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

  • setTestNow() public static

    设置一个 Chronos 实例(真实或模拟),当创建“现在”实例时将返回该实例。提供的实例将在以下条件下被具体返回

    • 调用静态 now() 方法,例如 Chronos::now()
    • 当传递 null(或空字符串)到构造函数或 parse() 时,例如 new Chronos(null)
    • 当将字符串“now”传递给构造函数或 parse() 时,例如 new Chronos('now')
    • 当将包含所需时间的字符串传递给 Chronos::parse() 时
  • setTime() public

    设置时间。

  • setTimeFromTimeString() public

    通过时间字符串设置时间。

  • setTimestamp() public

    根据 Unix 时间戳设置日期和时间。

  • setTimezone() public

    从字符串或对象设置实例的时区。

  • setToStringFormat() public static

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

  • setWeekEndsAt() public static

    设置一周的最后一天

  • setWeekStartsAt() public static

    设置一周的第一天

  • setWeekendDays() public static

    设置周末

  • startOfCentury() public

    将日期设置为世纪的第一天,时间设置为 00:00:00

  • startOfDay() public

    将时间设置为 00:00:00

  • startOfDecade() public

    将日期设置为十年的第一天,时间设置为 00:00:00

  • startOfMonth() public

    将日期设置为月的第一天,时间设置为 00:00:00

  • startOfWeek() public

    将日期设置为一周的第一天(在 $weekStartsAt 中定义)并将时间设置为 00:00:00

  • startOfYear() public

    将日期设置为年的第一天,时间设置为 00:00:00

  • subDays() public

    从实例中删除天数

  • subHours() public

    从实例中删除小时

  • subMinutes() public

    从实例中删除分钟

  • subMonths() public

    从实例中删除月

  • subMonthsWithOverflow() public

    在实例中添加带溢出的月份。正 $value 向前移动,负 $value 向后移动。

  • subSeconds() public

    从实例中删除秒

  • subWeekdays() public

    从实例中删除工作日

  • subWeeks() public

    从实例中删除周

  • subYears() public

    从实例中删除年。

  • subYearsWithOverflow() public

    从实例中删除带溢出的年

  • timeAgoInWords() public

    根据当前时间与该对象之间的时间差返回相对日期或格式化的绝对日期。

  • timestamp() public

    设置实例的时间戳

  • toAtomString() public

    将实例格式化为 ATOM

  • toCookieString() public

    将实例格式化为 COOKIE

  • toDateString() public

    将实例格式化为日期

  • 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\ChronosDateCake\Chronos\ChronosTimeDateTimeInterface|string|int|null $time = 'now', DateTimeZone|string|null $timezone = null)

创建一个新的 Chronos 实例。

有关此构造函数返回测试实例的可能性,请参阅测试辅助部分(特别是 static::setTestNow())。

参数
Cake\Chronos\ChronosDateCake\Chronos\ChronosTimeDateTimeInterface|string|int|null $time optional

固定或相对时间

DateTimeZone|string|null $timezone optional

实例的时区

__debugInfo() ¶ public

__debugInfo(): array

返回用于调试的属性。

返回
array

__get() ¶ public

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

获取对象的一部分

参数
string $name

要读取的属性名称。

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

__isset() ¶ public

__isset(string $name): bool

检查对象上是否存在属性

参数
string $name

要检查的属性名称。

返回
bool

__toString() ¶ public

__toString(): string

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

返回
string

_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

应显示日期的语言环境名称。

返回
string

_parseDateTime() ¶ protected static

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

解析传递的或配置的日期时间格式的提供的字符串后,返回一个新的 Time 对象。此方法依赖于区域设置。传递给此函数的任何字符串将被解释为依赖于区域设置的字符串。

与 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

addDays() ¶ public

addDays(int $value): static

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

参数
int $value

要添加的天数。

返回
static

addHours() ¶ public

addHours(int $value): static

在实例中添加小时数。正 $value 向前移动,负 $value 向后移动。

参数
int $value

要添加的小时数。

返回
static

addMinutes() ¶ public

addMinutes(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

addSeconds() ¶ public

addSeconds(int $value): static

在实例中添加秒数。正 $value 向前移动,负 $value 向后移动。

参数
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

average() ¶ public

average(DateTimeInterface|null $other = null): static

将当前实例修改为给定实例(默认现在)和当前实例的平均值。

参数
DateTimeInterface|null $other optional

要比较的实例。

返回
static

between() ¶ public

between(DateTimeInterface $start, DateTimeInterface $end, bool $equals = true): bool

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

参数
DateTimeInterface $start

目标范围的开始

DateTimeInterface $end

目标范围的结束

bool $equals optional

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

返回
bool

closest() ¶ public

closest(DateTimeInterface $first, DateTimeInterface $second, DateTimeInterface ...$others): static

获取与实例最接近的日期。

参数
DateTimeInterface $first

要比较的实例。

DateTimeInterface $second

要比较的实例。

DateTimeInterface ...$others

要比较的其他实例。

返回
static

create() ¶ public static

create(int|null $year = null, int|null $month = null, int|null $day = null, int|null $hour = null, int|null $minute = null, int|null $second = null, int|null $microsecond = null, DateTimeZone|string|null $timezone = null): static

从特定的日期和时间创建一个实例。

如果 $year、$month 或 $day 中的任何一个设置为 null,则将使用它们现在的值。

如果 $hour 为 null,则它将设置为其现在的值,$minute、$second 和 $microsecond 的默认值将为其现在的值。如果 $hour 不为 null,则 $minute、$second 和 $microsecond 的默认值将为 0。

参数
int|null $year optional

要创建实例的年份。

int|null $month optional

要创建实例的月份。

int|null $day optional

要创建实例的日期。

int|null $hour optional

要创建实例的小时。

int|null $minute optional

要创建实例的分钟。

int|null $second optional

要创建实例的秒。

int|null $microsecond optional

要创建实例的毫秒。

DateTimeZone|string|null $timezone optional

新的实例应使用的 DateTimeZone 对象或时区名称。

返回
static

createFromArray() ¶ public static

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

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

'year'、'month' 和 'day' 值必须全部设置日期。时间值全部默认为 0。

'timezone' 值可以是 \DateTimeZone 支持的任何格式。

允许的值

  • year
  • month
  • day
  • hour
  • minute
  • second
  • microsecond
  • meridian ('am' 或 'pm')
  • timezone
参数
array<int|string> $values

日期和时间值的数组。

返回
static

createFromDate() ¶ public static

createFromDate(int|null $year = null, int|null $month = null, int|null $day = null, DateTimeZone|string|null $timezone = null): static

仅从日期创建一个实例。时间部分设置为现在。

参数
int|null $year optional

要创建实例的年份。

int|null $month optional

要创建实例的月份。

int|null $day optional

要创建实例的日期。

DateTimeZone|string|null $timezone optional

新的实例应使用的 DateTimeZone 对象或时区名称。

返回
static

createFromFormat() ¶ public static

createFromFormat(string $format, string $time, DateTimeZone|string|null $timezone = null): static

从特定格式创建一个实例

参数
string $format

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

string $time

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

DateTimeZone|string|null $timezone optional

新的实例应使用的 DateTimeZone 对象或时区名称。

返回
static
抛出
InvalidArgumentException

createFromTime() ¶ public static

createFromTime(int|null $hour = null, int|null $minute = null, int|null $second = null, int|null $microsecond = null, DateTimeZone|string|null $timezone = null): static

仅从时间创建一个实例。日期部分设置为今天。

参数
int|null $hour optional

要创建实例的小时。

int|null $minute optional

要创建实例的分钟。

int|null $second optional

要创建实例的秒。

int|null $microsecond optional

要创建实例的毫秒。

DateTimeZone|string|null $timezone optional

新的实例应使用的 DateTimeZone 对象或时区名称。

返回
static

createFromTimestamp() ¶ public static

createFromTimestamp(float|int $timestamp, DateTimeZone|string|null $timezone = null): static

从时间戳创建一个实例

参数
float|int $timestamp

要创建实例的时间戳。

DateTimeZone|string|null $timezone optional

新的实例应使用的 DateTimeZone 对象或时区名称。

返回
static

createInterval() ¶ public static

createInterval(int|null $years = null, int|null $months = null, int|null $weeks = null, int|null $days = null, int|null $hours = null, int|null $minutes = null, int|null $seconds = null, int|null $microseconds = null): DateInterval

从指定的 value 创建一个新的 DateInterval 实例。

参数
int|null $years optional

要使用的年份。

int|null $months optional

要使用的月份。

int|null $weeks optional

要使用的星期。

int|null $days optional

要使用的日期。

int|null $hours optional

要使用的小时。

int|null $minutes optional

要使用的分钟。

int|null $seconds optional

要使用的秒数。

int|null $microseconds optional

要使用的微秒数。

返回
DateInterval

day() ¶ public

day(int $value): static

设置实例的天数

参数
int $value

日期值。

返回
static

diff() ¶ public

diff(DateTimeInterface $target, bool $absolute = false): DateInterval

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

参数
DateTimeInterface $target

目标实例

bool $absolute optional

是否强制间隔为正数

返回
DateInterval

diffFiltered() ¶ public

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

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

参数
DateInterval $interval

要遍历的间隔

callable $callback

用于过滤的回调函数。

DateTimeInterface|null $other optional

要进行差异比较的实例。

bool $absolute optional

获取差异的绝对值

int $options optional

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

返回
int

diffForHumans() ¶ public

diffForHumans(DateTimeInterface|null $other = null, bool $absolute = false): string

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

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

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

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

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

参数
DateTimeInterface|null $other optional

要比较的日期时间。

bool $absolute optional

删除时间差异修饰符(例如 ago,after 等)

返回
string

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(DateTimeInterface|null $other = null, bool $absolute = true): int

获取天数的差异

参数
DateTimeInterface|null $other optional

要进行差异比较的实例。

bool $absolute optional

获取差异的绝对值

返回
int

diffInDaysFiltered() ¶ public

diffInDaysFiltered(callable $callback, DateTimeInterface|null $other = null, bool $absolute = true, int $options = 0): int

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

参数
callable $callback

用于过滤的回调函数。

DateTimeInterface|null $other optional

要进行差异比较的实例。

bool $absolute optional

获取差异的绝对值

int $options optional

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

返回
int

diffInHours() ¶ public

diffInHours(DateTimeInterface|null $other = null, bool $absolute = true): int

获取小时数的差异

参数
DateTimeInterface|null $other optional

要进行差异比较的实例。

bool $absolute optional

获取差异的绝对值

返回
int

diffInHoursFiltered() ¶ public

diffInHoursFiltered(callable $callback, DateTimeInterface|null $other = null, bool $absolute = true, int $options = 0): int

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

参数
callable $callback

用于过滤的回调函数。

DateTimeInterface|null $other optional

要进行差异比较的实例。

bool $absolute optional

获取差异的绝对值

int $options optional

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

返回
int

diffInMinutes() ¶ public

diffInMinutes(DateTimeInterface|null $other = null, bool $absolute = true): int

获取分钟数的差异

参数
DateTimeInterface|null $other optional

要进行差异比较的实例。

bool $absolute optional

获取差异的绝对值

返回
int

diffInMonths() ¶ public

diffInMonths(DateTimeInterface|null $other = null, bool $absolute = true): int

获取月份的差异

参数
DateTimeInterface|null $other optional

要进行差异比较的实例。

bool $absolute optional

获取差异的绝对值

返回
int

diffInMonthsIgnoreTimezone() ¶ public

diffInMonthsIgnoreTimezone(DateTimeInterface|null $other = null, bool $absolute = true): int

忽略时区获取月份的差异。这意味着月份是在指定时区中计算的,没有先转换为 UTC。这将防止日期更改,这可能会更改月份。

例如,如果比较 2019-06-01 Asia/Tokyo 和 2019-10-01 Asia/Tokyo,则结果将是 4 个月,而不是使用正常的 DateTime::diff() 时得到的 3 个月。

参数
DateTimeInterface|null $other optional

要进行差异比较的实例。

bool $absolute optional

获取差异的绝对值

返回
int

diffInSeconds() ¶ public

diffInSeconds(DateTimeInterface|null $other = null, bool $absolute = true): int

获取秒数的差异

参数
DateTimeInterface|null $other optional

要进行差异比较的实例。

bool $absolute optional

获取差异的绝对值

返回
int

diffInWeekdays() ¶ public

diffInWeekdays(DateTimeInterface|null $other = null, bool $absolute = true, int $options = 0): int

获取工作日的差异

参数
DateTimeInterface|null $other optional

要进行差异比较的实例。

bool $absolute optional

获取差异的绝对值

int $options optional

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

返回
int

diffInWeekendDays() ¶ public

diffInWeekendDays(DateTimeInterface|null $other = null, bool $absolute = true, int $options = 0): int

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

参数
DateTimeInterface|null $other optional

要进行差异比较的实例。

bool $absolute optional

获取差异的绝对值

int $options optional

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

返回
int

diffInWeeks() ¶ public

diffInWeeks(DateTimeInterface|null $other = null, bool $absolute = true): int

获取星期数的差异

参数
DateTimeInterface|null $other optional

要进行差异比较的实例。

bool $absolute optional

获取差异的绝对值

返回
int

diffInYears() ¶ public

diffInYears(DateTimeInterface|null $other = null, bool $absolute = true): int

获取年份的差异

参数
DateTimeInterface|null $other optional

要进行差异比较的实例。

bool $absolute optional

获取差异的绝对值

返回
int

disableLenientParsing() ¶ public static

disableLenientParsing(): void

为区域设置格式启用宽松解析。

返回
void

enableLenientParsing() ¶ public static

enableLenientParsing(): void

为区域设置格式启用宽松解析。

返回
void

endOfCentury() ¶ public

endOfCentury(): static

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

返回
static

endOfDay() ¶ public

endOfDay(bool $microseconds = false): static

将时间设置为 23:59:59 或 23:59:59.999999,如果 $microseconds 为真。

参数
bool $microseconds optional

是否设置微秒数

返回
static

endOfDecade() ¶ public

endOfDecade(): static

将日期设置为十年末,时间设置为 23:59:59

返回
static

endOfMonth() ¶ public

endOfMonth(): static

将日期设置为月底,时间设置为 23:59:59

返回
static

endOfWeek() ¶ public

endOfWeek(): static

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

返回
static

endOfYear() ¶ public

endOfYear(): static

将日期设置为年末,时间设置为 23:59:59

返回
static

equals() ¶ public

equals(DateTimeInterface $other): bool

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

参数
DateTimeInterface $other

要比较的实例。

返回
bool

farthest() ¶ public

farthest(DateTimeInterface $first, DateTimeInterface $second, DateTimeInterface ...$others): static

获取与实例最远的日期。

参数
DateTimeInterface $first

要比较的实例。

DateTimeInterface $second

要比较的实例。

DateTimeInterface ...$others

要比较的其他实例。

返回
static

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

fromNow() ¶ public static

fromNow(DateTimeInterface $other): DateInterval|bool

获取给定时间剩余时间的便捷方法。

参数
DateTimeInterface $other

要获取剩余时间的日期。

返回
DateInterval|bool

getDefaultLocale() ¶ public static

getDefaultLocale(): string|null

获取默认区域设置。

返回
string|null

getLastErrors() ¶ public static

getLastErrors(): array|false

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

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

返回
array|false

getOffset() ¶ public

getOffset(): int

返回时区偏移量。

返回
int

getTestNow() ¶ public static

getTestNow(): Cake\Chronos\Chronos|null

获取创建“现在”实例时要返回的 Chronos 实例(真实或模拟)。

返回
Cake\Chronos\Chronos|null

getTimestamp() ¶ public

getTimestamp(): int

获取此实例的 Unix 时间戳。

返回
int

getTimezone() ¶ public

getTimezone(): DateTimeZone

返回为此实例设置的时区。

返回
DateTimeZone

getWeekEndsAt() ¶ public static

getWeekEndsAt(): int

获取一周的最后一天

返回
int

getWeekStartsAt() ¶ public static

getWeekStartsAt(): int

获取一周的第一天

返回
int

getWeekendDays() ¶ public static

getWeekendDays(): array

获取周末

返回
array

greaterThan() ¶ public

greaterThan(DateTimeInterface $other): bool

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

参数
DateTimeInterface $other

要比较的实例。

返回
bool

greaterThanOrEquals() ¶ public

greaterThanOrEquals(DateTimeInterface $other): bool

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

参数
DateTimeInterface $other

要比较的实例。

返回
bool

hasRelativeKeywords() ¶ public static

hasRelativeKeywords(string|null $time): bool

确定时间字符串中是否包含相对关键字,用于创建相对于现在的日期以供测试实例使用。例如:下周二

参数
string|null $time

要检查的时间字符串。

返回
bool

hasTestNow() ¶ public static

hasTestNow(): bool

确定是否设置了有效的测试实例。有效的测试实例是任何非空值。

返回
bool

hour() ¶ public

hour(int $value): static

设置实例的小时数

参数
int $value

小时值。

返回
static

i18nFormat() ¶ public

i18nFormat(array<int>|string|int|null $format = null, DateTimeZone|string|null $timezone = null, string|null $locale = null): string|int

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

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

除了 IntlDateFormatter 常量和日期格式字符串之外,还可以使用 DateTime::UNIX_TIMESTAMP_FORMAT 获取 Unix 时间戳

示例

$time = new DateTime('2014-04-20 22:10');
$time->i18nFormat(); // outputs '4/20/14, 10:10 PM' for the en-US locale
$time->i18nFormat(\IntlDateFormatter::FULL); // Use the full date and time format
$time->i18nFormat([\IntlDateFormatter::FULL, \IntlDateFormatter::SHORT]); // Use full date but short time format
$time->i18nFormat('yyyy-MM-dd HH:mm:ss'); // outputs '2014-04-20 22:10'
$time->i18nFormat(DateTime::UNIX_TIMESTAMP_FORMAT); // outputs '1398031800'

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

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

如果需要以不同于此 Time 对象所使用的时间区域显示日期,而无需更改其内部状态,则可以将时间区域字符串或对象作为第二个参数传递。

最后,如果需要使用不同的语言环境来显示此时间对象,则将语言环境字符串作为此函数的第三个参数传递。

示例

$time = new Time('2014-04-20 22:10');
$time->i18nFormat(null, null, 'de-DE');
$time->i18nFormat(\IntlDateFormatter::FULL, 'Europe/Berlin', 'de-DE');

可以通过 DateTime::setDefaultLocale() 控制使用的默认语言环境。如果为空,则默认值将取自 intl.default_locale ini 配置。

参数
array<int>|string|int|null $format optional

格式字符串。

DateTimeZone|string|null $timezone optional

要显示日期的时间区域字符串或 DateTimeZone 对象。此对象存储的时间区域不会更改。

string|null $locale optional

要显示日期的语言环境名称(例如 pt-BR)

返回
string|int

instance() ¶ public static

instance(DateTimeInterface $other): static

从 DateTimeInterface 创建一个实例

参数
DateTimeInterface $other

要转换的日期时间实例。

返回
static

isBirthday() ¶ public

isBirthday(DateTimeInterface|null $other = null): bool

检查是否为生日。比较两个日期的日期/月份值。

参数
DateTimeInterface|null $other optional

要比较的实例,或 null 以使用当前日期。

返回
bool

isFirstHalf() ¶ public

isFirstHalf(): bool

确定实例是否在前半年的时间范围内。

返回
bool

isFriday() ¶ public

isFriday(): bool

检查这天是否为星期五。

返回
bool

isFuture() ¶ public

isFuture(): bool

确定实例是否在将来,即大于(晚于)现在。

返回
bool

isLastMonth() ¶ public

isLastMonth(): bool

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

返回
bool

isLastWeek() ¶ public

isLastWeek(): bool

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

返回
bool

isLastYear() ¶ public

isLastYear(): bool

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

返回
bool

isLeapYear() ¶ public

isLeapYear(): bool

确定实例是否为闰年。

返回
bool

isMonday() ¶ public

isMonday(): bool

检查这天是否为星期一。

返回
bool

isNextMonth() ¶ public

isNextMonth(): bool

确定实例是否在下一个月内。

返回
bool

isNextWeek() ¶ public

isNextWeek(): bool

确定实例是否在下一周内。

返回
bool

isNextYear() ¶ public

isNextYear(): bool

确定实例是否在下一年内。

返回
bool

isPast() ¶ public

isPast(): bool

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

返回
bool

isSameDay() ¶ public

isSameDay(DateTimeInterface $other): bool

检查传入的日期是否与实例的当前日期相同。

参数
DateTimeInterface $other

要检查的实例。

返回
bool

isSameMonth() ¶ public

isSameMonth(DateTimeInterface $other): bool

返回传入的日期是否与实例的月份和年份相同。

参数
DateTimeInterface $other

要检查的实例。

返回
bool

isSameYear() ¶ public

isSameYear(DateTimeInterface $other): bool

返回传入的日期是否与实例的年份相同。

参数
DateTimeInterface $other

要检查的实例。

返回
bool

isSaturday() ¶ public

isSaturday(): bool

检查这天是否为星期六。

返回
bool

isSecondHalf() ¶ public

isSecondHalf(): bool

确定实例是否在后半年时间范围内。

返回
bool

isSunday() ¶ public

isSunday(): bool

检查这天是否为星期日。

返回
bool

isThisMonth() ¶ public

isThisMonth(): bool

如果此对象表示当前月内的日期,则返回 true。

返回
bool

isThisWeek() ¶ public

isThisWeek(): bool

如果此对象表示当前周内的日期,则返回 true。

返回
bool

isThisYear() ¶ public

isThisYear(): bool

如果此对象表示当前年内的日期,则返回 true。

返回
bool

isThursday() ¶ public

isThursday(): bool

检查这天是否为星期四。

返回
bool

isToday() ¶ public

isToday(): bool

确定实例是否为今天。

返回
bool

isTomorrow() ¶ public

isTomorrow(): bool

确定实例是否为明天。

返回
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(): bool

确定实例是否为昨天。

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

lenientParsingEnabled() ¶ public static

lenientParsingEnabled(): bool

获取区域设置格式解析是否设置为宽松。

返回
bool

lessThan() ¶ public

lessThan(DateTimeInterface $other): bool

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

参数
DateTimeInterface $other

要比较的实例。

返回
bool

lessThanOrEquals() ¶ public

lessThanOrEquals(DateTimeInterface $other): bool

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

参数
DateTimeInterface $other

要比较的实例。

返回
bool

listTimezones() ¶ public static

listTimezones(string|int|null $filter = null, string|null $country = null, array<string, mixed>|bool $options = []): array

获取时区标识符列表。

参数
string|int|null $filter 可选

用于过滤标识符的正则表达式或 DateTimeZone 类常量之一

string|null $country 可选

一个两位的 ISO 3166-1 兼容国家代码。此选项仅在 $filter 设置为 DateTimeZone::PER_COUNTRY 时使用

array<string, mixed>|bool $options 可选

如果为 true(默认值),则按主要区域对标识符列表进行分组。否则,将返回一个包含 group、abbr、before 和 after 键的数组。将 group 和 abbr 设置为 true 将对结果进行分组并在显示值中追加时区缩写。设置 before 和 after 以自定义缩写的包装器。

返回
array

max() ¶ public

max(DateTimeInterface|null $other = null): static

获取给定实例(默认值为现在)和当前实例之间的最大实例。

参数
DateTimeInterface|null $other optional

要比较的实例。

返回
static

maxValue() ¶ public static

maxValue(): static

为最大的支持日期创建一个实例。

返回
static

microsecond() ¶ public

microsecond(int $value): static

设置实例的微秒。

参数
int $value

微秒值。

返回
static

min() ¶ public

min(DateTimeInterface|null $other = null): static

获取给定实例(默认值为现在)和当前实例之间的最小实例。

参数
DateTimeInterface|null $other optional

要比较的实例。

返回
static

minValue() ¶ public static

minValue(): static

为最小的支持日期创建一个实例。

返回
static

minute() ¶ public

minute(int $value): static

设置实例的分钟。

参数
int $value

分钟值。

返回
static

modify() ¶ public

modify(string $modifier): static

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

参数
string $modifier

日期修饰符

返回
static
抛出
InvalidArgumentException
另请参阅
https://php.ac.cn/manual/en/datetimeimmutable.modify.php

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(DateTimeZone|string|null $timezone = null, string|null $locale = null): string

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

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

参数
DateTimeZone|string|null $timezone optional

要显示日期的时间区域字符串或 DateTimeZone 对象。此对象存储的时间区域不会更改。

string|null $locale optional

要显示日期的语言环境名称(例如 pt-BR)

返回
string

notEquals() ¶ public

notEquals(DateTimeInterface $other): bool

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

参数
DateTimeInterface $other

要比较的实例。

返回
bool

now() ¶ public static

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

获取当前日期和时间的实例。

参数
DateTimeZone|string|null $timezone optional

DateTimeZone 对象或时区名称。

返回
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\ChronosDateCake\Chronos\ChronosTimeDateTimeInterface|string|int|null $time = 'now', DateTimeZone|string|null $timezone = null): static

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

参数
Cake\Chronos\ChronosDateCake\Chronos\ChronosTimeDateTimeInterface|string|int|null $time optional

要解析的 strtotime 兼容字符串

DateTimeZone|string|null $timezone optional

DateTimeZone 对象或时区名称。

返回
static

parseDate() ¶ public static

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

根据传递或配置的日期时间格式,解析提供的 $date 字符串后,返回一个新的 Time 对象。此方法与区域设置相关,传递给此函数的任何字符串都将被解释为与区域设置相关的字符串。

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

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

示例

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

要解析的日期字符串。

array|string|int|null $format 可选

IntlDateFormatter 接受的任何格式。

返回
static|null

parseDateTime() ¶ public static

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

解析传递的或配置的日期时间格式的提供的字符串后,返回一个新的 Time 对象。此方法依赖于区域设置。传递给此函数的任何字符串将被解释为依赖于区域设置的字符串。

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

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

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

示例

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

要解析的时间字符串。

array<int>|string|int|null $format optional

IntlDateFormatter 接受的任何格式。

DateTimeZone|string|null $tz optional

实例的时区

返回
static|null

parseTime() ¶ public static

parseTime(string $time, array|string|int|null $format = null): static|null

根据传递或配置的日期时间格式,解析提供的 $time 字符串后,返回一个新的 Time 对象。此方法与区域设置相关,传递给此函数的任何字符串都将被解释为与区域设置相关的字符串。

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

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

示例

 $time = DateTime::parseTime('11:23pm');
参数
string $time

要解析的时间字符串。

array|string|int|null $format 可选

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

将用于将此类型的实例转换为字符串的格式重置为默认值。

返回
void

rolloverTime() ¶ protected static

rolloverTime(int|null $value, int $max): int|null

更新值为剩余值,并返回时间单位的翻转值,如果未翻转,则返回 null。

参数
int|null $value

时间单位值

int $max

时间单位最大值

返回
int|null

safeCreateDateTimeZone() ¶ protected static

safeCreateDateTimeZone(DateTimeZone|string|null $object): DateTimeZone

从字符串或 DateTimeZone 创建 DateTimeZone。

参数
DateTimeZone|string|null $object

要转换的值。

返回
DateTimeZone
抛出
InvalidArgumentException

second() ¶ public

second(int $value): static

设置实例的秒。

参数
int $value

秒值。

返回
static

secondsSinceMidnight() ¶ public

secondsSinceMidnight(): int

从午夜开始的秒数。

返回
int

secondsUntilEndOfDay() ¶ public

secondsUntilEndOfDay(): int

到 23:59:59 的秒数。

返回
int

setDate() ¶ public

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

设置日期。

参数
int $year

要设置的年份。

int $month

要设置的月份。

int $day

要设置的日期。

返回
static

setDateTime() ¶ public

setDateTime(int $year, int $month, int $day, int $hour, int $minute, int $second = 0): static

设置日期和时间。

参数
int $year

要设置的年份。

int $month

要设置的月份。

int $day

要设置的日期。

int $hour

要设置的小时。

int $minute

要设置的分钟。

int $second 可选

要设置的秒数。

返回
static

setDefaultLocale() ¶ public static

setDefaultLocale(string|null $locale = null): void

设置默认区域设置。

设置为 null 以使用 IntlDateFormatter 默认值。

参数
string|null $locale optional

要使用的默认区域设置字符串。

返回
void

setISODate() ¶ public

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

根据 ISO 8601 标准设置日期。

参数
int $year

日期的年份。

int $week

日期的周数。

int $dayOfWeek 可选

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

返回
static

setJsonEncodeFormat() ¶ public static

setJsonEncodeFormat(Closure|array|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 中指定的模式。

可以提供包含 2 个常量的数组。在这种情况下,第一个位置将用于格式化对象的日期部分,第二个位置将用于格式化时间部分。

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

参数
Closure|array|string|int $format

格式。

返回
void
另请参阅
\Cake\I18n\DateTime::i18nFormat()

setTestNow() ¶ public static

setTestNow(Cake\Chronos\Chronos|string|null $testNow = null): void

设置一个 Chronos 实例(真实或模拟),当创建“现在”实例时将返回该实例。提供的实例将在以下条件下被具体返回

  • 调用静态 now() 方法,例如 Chronos::now()
  • 当传递 null(或空字符串)到构造函数或 parse() 时,例如 new Chronos(null)
  • 当将字符串“now”传递给构造函数或 parse() 时,例如 new Chronos('now')
  • 当将包含所需时间的字符串传递给 Chronos::parse() 时

请注意,时区参数已从上面的示例中省略,并且没有任何影响,因为无论其值如何,模拟值都将返回。

要清除测试实例,请使用默认参数 null 调用此方法。

参数
Cake\Chronos\Chronos|string|null $testNow 可选

用于所有未来实例的实例。

返回
void

setTime() ¶ public

setTime(int $hours, int $minutes, int $seconds = 0, int $microseconds = 0): static

设置时间。

参数
int $hours

时间的时数

int $minutes

时间的分钟数

int $seconds 可选

时间的秒数

int $microseconds 可选

时间的微秒数

返回
static

setTimeFromTimeString() ¶ public

setTimeFromTimeString(string $time): static

通过时间字符串设置时间。

参数
string $time

时间字符串。

返回
static

setTimestamp() ¶ public

setTimestamp(int $timestamp): static

根据 Unix 时间戳设置日期和时间。

参数
int $timestamp

表示日期的 Unix 时间戳

返回
static

setTimezone() ¶ public

setTimezone(DateTimeZone|string $value): static

从字符串或对象设置实例的时区。

参数
DateTimeZone|string $value

要使用的 DateTimeZone 对象或时区名称。

返回
static

setToStringFormat() ¶ public static

setToStringFormat(array<int>|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 中指定的模式。

可以提供包含 2 个常量的数组。在这种情况下,第一个位置将用于格式化对象的日期部分,第二个位置将用于格式化时间部分。

参数
array<int>|string|int $format

格式。

返回
void

setWeekEndsAt() ¶ public static

setWeekEndsAt(int $day): void

设置一周的最后一天

参数
int $day

星期结束的日期。

返回
void

setWeekStartsAt() ¶ public static

setWeekStartsAt(int $day): void

设置一周的第一天

参数
int $day

星期开始的日期。

返回
void

setWeekendDays() ¶ public static

setWeekendDays(array $days): void

设置周末

参数
array $days

哪些日期是“周末”。

返回
void

startOfCentury() ¶ public

startOfCentury(): static

将日期设置为世纪的第一天,时间设置为 00:00:00

返回
static

startOfDay() ¶ public

startOfDay(): static

将时间设置为 00:00:00

返回
static

startOfDecade() ¶ public

startOfDecade(): static

将日期设置为十年的第一天,时间设置为 00:00:00

返回
static

startOfMonth() ¶ public

startOfMonth(): static

将日期设置为月的第一天,时间设置为 00:00:00

返回
static

startOfWeek() ¶ public

startOfWeek(): static

将日期设置为一周的第一天(在 $weekStartsAt 中定义)并将时间设置为 00:00:00

返回
static

startOfYear() ¶ public

startOfYear(): static

将日期设置为年的第一天,时间设置为 00:00:00

返回
static

subDays() ¶ public

subDays(int $value): static

从实例中删除天数

参数
int $value

要移除的天数。

返回
static

subHours() ¶ public

subHours(int $value): static

从实例中删除小时

参数
int $value

要移除的小时数。

返回
static

subMinutes() ¶ public

subMinutes(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

subSeconds() ¶ public

subSeconds(int $value): static

从实例中删除秒

参数
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 => 表示“现在”时间的另一个 Time 对象
  • format => 如果相对时间长于由 end 指定的持续时间,则为回退格式
  • accuracy => 指定日期的描述精度(数组)
    • year => 如果年份 > 0 时的格式(默认“day”)
    • month => 如果月份 > 0 时的格式(默认“day”)
    • week => 如果周数 > 0 时的格式(默认“day”)
    • day => 如果周数 > 0 时的格式(默认“hour”)
    • hour => 如果小时数 > 0 时的格式(默认“minute”)
    • minute => 如果分钟数 > 0 时的格式(默认“minute”)
    • second => 如果秒数 > 0 时的格式(默认“second”)
  • end => 相对时间讲述的结束
  • relativeString => 输出相对时间时的 printf 兼容字符串
  • absoluteString => 输出绝对时间时的 printf 兼容字符串
  • timezone => 要在其中格式化时间戳的用户时区。

相对日期看起来像这样

  • 3 周,4 天前
  • 15 秒前

默认日期格式为 d/M/YY,例如:在 18/2/09。格式化是在内部使用 i18nFormat 完成的,请参阅方法了解有效的格式化字符串

返回的字符串包含“ago”或“on”,并假设您将在函数输出之前正确添加一个词,例如“Posted”。

注意:如果差值为一周或更长,则最低精度级别为 day

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

选项数组。

返回
string

timestamp() ¶ public

timestamp(int $value): static

设置实例的时间戳

参数
int $value

要设置的时间戳值。

返回
static

toAtomString() ¶ public

toAtomString(): string

将实例格式化为 ATOM

返回
string

toCookieString() ¶ public

toCookieString(): string

将实例格式化为 COOKIE

返回
string

toDateString() ¶ public

toDateString(): string

将实例格式化为日期

返回
string

toDateTimeString() ¶ public

toDateTimeString(): string

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

返回
string

toDayDateTimeString() ¶ public

toDayDateTimeString(): string

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

返回
string

toFormattedDateString() ¶ public

toFormattedDateString(): string

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

返回
string

toIso8601String() ¶ public

toIso8601String(): string

将实例格式化为 ISO8601

返回
string

toNative() ¶ public

toNative(): DateTimeImmutable

返回 DateTimeImmutable 实例

此方法返回没有 Chronos 扩展的 PHP DateTimeImmutable。

返回
DateTimeImmutable

toQuarter() ¶ public

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

返回季度

参数
bool $range 可选

范围。

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

要使用的时区。

返回
static

tomorrow() ¶ public static

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

创建明天的实例

参数
DateTimeZone|string|null $timezone optional

新的实例应使用的 DateTimeZone 对象或时区名称。

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

新的实例应使用的 DateTimeZone 对象或时区名称。

返回
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 中指定的模式。

可以提供包含 2 个常量的数组。在这种情况下,第一个位置将用于格式化对象的日期部分,第二个位置将用于格式化时间部分。

类型
Closure|array<int>|string|int

$_toStringFormat ¶ protected static

使用 Cake\I18n\DateTime::i18nFormat() 和 __toString 格式化时间时要使用的格式。此格式也由 parseDateTime() 使用。

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

可以提供包含 2 个常量的数组。在这种情况下,第一个位置将用于格式化对象的日期部分,第二个位置将用于格式化时间部分。

类型
array<int>|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>

$defaultLocale ¶ protected static

用于显示格式化日期字符串的默认语言环境。

请使用 static::setDefaultLocale() 和 static::getDefaultLocale() 代替。

类型
string|null

$diffFormatter ¶ protected static

差异格式化对象的实例。

类型
Cake\Chronos\DifferenceFormatterInterface|null

$dst ¶ public @property-read

夏令时指示器,如果为夏令时,则为 true,否则为 false。

类型
bool

$formatters ¶ protected static

日期格式化器的内存缓存。

类型
array<string,IntlDateFormatter>

$half ¶ public @property-read

一年的前半段,1 代表 1 月到 6 月,2 代表 7 月到 12 月。

类型
int<1, 2>

$hour ¶ public @property-read

类型
int<0, 23>

$lastErrors ¶ protected static

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

类型
array|false

$lenientParsing ¶ protected static

是否为 IntlDateFormatter 启用宽松解析。

默认为 true,这也是 IntlDateFormatter 的默认值。

类型
bool

$local ¶ public @property-read

检查时区是否为本地时区,如果为本地时区,则为 true,否则为 false。

类型
bool

$micro ¶ public @property-read

类型
int<0, 999999>

$microsecond ¶ public @property-read

类型
int<0, 999999>

$minute ¶ public @property-read

类型
int<0, 59>

$month ¶ public @property-read

类型
int<1, 12>

$niceFormat ¶ public static

使用 Cake\I18n\DateTime::nice() 格式化时间时要使用的格式。

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

可以提供包含 2 个常量的数组。在这种情况下,第一个位置将用于格式化对象的日期部分,第二个位置将用于格式化时间部分。

类型
array<int>|string|int

$offset ¶ public @property-read

UTC 的时区偏移量(以秒为单位)。

类型
int

$offsetHours ¶ public @property-read

UTC 的时区偏移量(以小时为单位)。

类型
int

$quarter ¶ public @property-read

此实例的季度,从 1 到 4。

类型
int<1, 4>

$relativePattern ¶ protected static

相对时期的正则表达式。

类型
string

$second ¶ public @property-read

类型
int<0, 59>

$testNow ¶ protected static

创建 now 实例时要返回的测试 Chronos 实例。

Chronos 提供的所有日期/时间类只有一个测试时间点。这旨在模拟对“现在”的存根,这只是一个全局的事实。

类型
Cake\Chronos\Chronos|null

$timestamp ¶ public @property-read

自 Unix 纪元以来的秒数。

类型
int

$timezone ¶ public @property-read

当前时区。

类型
DateTimeZone

$timezoneName ¶ public @property-read

类型
string

$toStringFormat ¶ protected static

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

类型
string

$tz ¶ public @property-read

时区的别名。

类型
DateTimeZone

$tzName ¶ public @property-read

类型
string

$utc ¶ public @property-read

检查时区是否为 UTC,如果为 UTC,则为 true,否则为 false。

类型
bool

$weekEndsAt ¶ protected static

一周的最后一天。

类型
int

$weekOfMonth ¶ public @property-read

从 1 到 5。

类型
int<1, 5>

$weekOfYear ¶ public @property-read

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

类型
int<1, 53>

$weekStartsAt ¶ protected static

一周的第一天

类型
int

$weekendDays ¶ protected static

周末的日子

类型
array

$wordAccuracy ¶ public static

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

类型
array<string, string>

$wordEnd ¶ public static

相对时间描述的结束时间

类型
string

$wordFormat ¶ public static

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

类型
array<int>|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 文档 生成