DateTime 类
扩展内置 DateTime 类,提供便捷方法和本地化格式化辅助函数。
常量
- 
          
          intDAYS_PER_WEEK ¶7
- 
          
          stringDEFAULT_TO_STRING_FORMAT ¶'Y-m-d H:i:s'类型转换时,用于 __toString 方法的默认格式。 
- 
          
          intFRIDAY ¶5
- 
          
          intHOURS_PER_DAY ¶24
- 
          
          intMINUTES_PER_HOUR ¶60
- 
          
          intMONDAY ¶1
- 
          
          intMONTHS_PER_QUARTER ¶3
- 
          
          intMONTHS_PER_YEAR ¶12
- 
          
          intSATURDAY ¶6
- 
          
          intSECONDS_PER_MINUTE ¶60
- 
          
          intSUNDAY ¶7
- 
          
          intTHURSDAY ¶4
- 
          
          intTUESDAY ¶2
- 
          
          stringUNIX_TIMESTAMP_FORMAT ¶'unixTimestampFormat'将值序列化为 Unix 时间戳。 
- 
          
          intWEDNESDAY ¶3
- 
          
          intWEEKS_PER_YEAR ¶52
- 
          
          intYEARS_PER_CENTURY ¶100
- 
          
          intYEARS_PER_DECADE ¶10
属性概要
- 
        $_jsonEncodeFormat protected staticClosure|array<int>|string|int将此对象转换为 JSON 时要使用的格式。 
- 
        $_toStringFormat protected staticarray<int>|string|int使用 Cake\I18n\DateTime::i18nFormat()和__toString格式化时间时要使用的格式。此格式也由parseDateTime()使用。
- 
        $age public @property-readint使用默认参数执行 diffInYears()。 
- 
        $day public @property-readint<1, 31>
- 
        $dayOfWeek public @property-readint<1, 7>从 1(星期一)到 7(星期天)。 
- 
        $dayOfYear public @property-readint<0, 365>从 0 到 365。 
- 
        $days protected staticarray一周中各天的名称。 
- 
        $daysInMonth public @property-readint<1, 31>给定月份的天数。 
- 
        $defaultLocale protected staticstring|null用于显示格式化日期字符串的默认语言环境。 
- 
        $diffFormatter protected staticCake\Chronos\DifferenceFormatterInterface|null差异格式化对象的实例。 
- 
        $dst public @property-readbool夏令时指示器,如果为夏令时,则为 true,否则为 false。 
- 
        $formatters protected staticarray<string,IntlDateFormatter>日期格式化器的内存缓存。 
- 
        $half public @property-readint<1, 2>一年的前半段,1 代表 1 月到 6 月,2 代表 7 月到 12 月。 
- 
        $hour public @property-readint<0, 23>
- 
        $lastErrors protected staticarray|false上次调用 createFromFormat() 时的错误。 
- 
        $lenientParsing protected staticbool是否为 IntlDateFormatter 启用宽松解析。 
- 
        $local public @property-readbool检查时区是否为本地时区,如果为本地时区,则为 true,否则为 false。 
- 
        $micro public @property-readint<0, 999999>
- 
        $microsecond public @property-readint<0, 999999>
- 
        $minute public @property-readint<0, 59>
- 
        $month public @property-readint<1, 12>
- 
        $niceFormat public staticarray<int>|string|int使用 Cake\I18n\DateTime::nice()格式化时间时要使用的格式。
- 
        $offset public @property-readintUTC 的时区偏移量(以秒为单位)。 
- 
        $offsetHours public @property-readintUTC 的时区偏移量(以小时为单位)。 
- 
        $quarter public @property-readint<1, 4>此实例的季度,从 1 到 4。 
- 
        $relativePattern protected staticstring相对时期的正则表达式。 
- 
        $second public @property-readint<0, 59>
- 
        $testNow protected staticCake\Chronos\Chronos|null创建 now 实例时要返回的测试 Chronos 实例。 
- 
        $timestamp public @property-readint自 Unix 纪元以来的秒数。 
- 
        $timezone public @property-readDateTimeZone当前时区。 
- 
        $timezoneName public @property-readstring
- 
        $toStringFormat protected staticstring类型转换时,用于 __toString 方法的格式。 
- 
        $tz public @property-readDateTimeZone时区的别名。 
- 
        $tzName public @property-readstring
- 
        $utc public @property-readbool检查时区是否为 UTC,如果为 UTC,则为 true,否则为 false。 
- 
        $weekEndsAt protected staticint一周的最后一天。 
- 
        $weekOfMonth public @property-readint<1, 5>从 1 到 5。 
- 
        $weekOfYear public @property-readint<1, 53>ISO-8601 年的周数,从星期一开始算 
- 
        $weekStartsAt protected staticint一周的第一天 
- 
        $weekendDays protected staticarray周末的日子 
- 
        $wordAccuracy public staticarray<string, string>使用 DateTime::timeAgoInWords()格式化时间时使用的格式,差异小于DateTime::$wordEnd
- 
        $wordEnd public staticstring相对时间描述的结束时间 
- 
        $wordFormat public staticarray<int>|string|int使用 Cake\I18n\DateTime::timeAgoInWords()格式化时间时使用的格式,差异大于Cake\I18n\DateTime::$wordEnd
- 
        $year public @property-readint
- 
        $yearIso public @property-readint
方法摘要
- 
          __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
- 实例的时区 
__get() ¶ public
__get(string $name): DateTimeZone|string|float|int|bool获取对象的一部分
参数
- 
                string$name
- 要读取的属性名称。 
返回
DateTimeZone|string|float|int|bool抛出
InvalidArgumentException__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|nulladdDays() ¶ public
addDays(int $value): static在实例中添加天数。正 $value 向前移动,负 $value 向后移动。
参数
- 
                int$value
- 要添加的天数。 
返回
staticaddHours() ¶ public
addHours(int $value): static在实例中添加小时数。正 $value 向前移动,负 $value 向后移动。
参数
- 
                int$value
- 要添加的小时数。 
返回
staticaddMinutes() ¶ public
addMinutes(int $value): static在实例中添加分钟数。正 $value 向前移动,负 $value 向后移动。
参数
- 
                int$value
- 要添加的分钟数。 
返回
staticaddMonths() ¶ 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
- 要添加的月数。 
返回
staticaddMonthsWithOverflow() ¶ public
addMonthsWithOverflow(int $value): static在实例中添加带溢出的月份。正 $value 向前移动,负 $value 向后移动。
如果新的 ChronosDate 不存在,则天数溢出到下一个月。
示例
 (new Chronos('2012-01-30'))->addMonthsWithOverflow(1); // Results in 2013-03-01参数
- 
                int$value
- 要添加的月数。 
返回
staticaddSeconds() ¶ public
addSeconds(int $value): static在实例中添加秒数。正 $value 向前移动,负 $value 向后移动。
参数
- 
                int$value
- 要添加的秒数。 
返回
staticaddWeekdays() ¶ public
addWeekdays(int $value): static在实例中添加工作日。正 $value 向前移动,负 $value 向后移动。
参数
- 
                int$value
- 要添加的工作日数。 
返回
staticaddWeeks() ¶ public
addWeeks(int $value): static在实例中添加星期。正 $value 向前移动,负 $value 向后移动。
参数
- 
                int$value
- 要添加的周数。 
返回
staticaddYears() ¶ 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
- 要添加的年数。 
返回
staticaddYearsWithOverflow() ¶ public
addYearsWithOverflow(int $value): static在实例中添加带溢出的年份。正 $value 向前移动,负 $value 向后移动。
如果新的 ChronosDate 不存在,则天数溢出到下一个月。
示例
 (new Chronos('2012-02-29'))->addYearsWithOverflow(1); // Results in 2013-03-01参数
- 
                int$value
- 要添加的年数。 
返回
staticaverage() ¶ public
average(DateTimeInterface|null $other = null): static将当前实例修改为给定实例(默认现在)和当前实例的平均值。
参数
- 
                DateTimeInterface|null$other optional
- 要比较的实例。 
返回
staticbetween() ¶ public
between(DateTimeInterface $start, DateTimeInterface $end, bool $equals = true): bool确定实例是否在另外两个实例之间
参数
- 
                DateTimeInterface$start
- 目标范围的开始 
- 
                DateTimeInterface$end
- 目标范围的结束 
- 
                bool$equals optional
- 是否包含范围的开始和结束 
返回
boolclosest() ¶ public
closest(DateTimeInterface $first, DateTimeInterface $second, DateTimeInterface ...$others): static获取与实例最接近的日期。
参数
- 
                DateTimeInterface$first
- 要比较的实例。 
- 
                DateTimeInterface$second
- 要比较的实例。 
- 
                DateTimeInterface...$others
- 要比较的其他实例。 
返回
staticcreate() ¶ 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 对象或时区名称。 
返回
staticcreateFromArray() ¶ 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
- 日期和时间值的数组。 
返回
staticcreateFromDate() ¶ 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 对象或时区名称。 
返回
staticcreateFromFormat() ¶ 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抛出
InvalidArgumentExceptioncreateFromTime() ¶ 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 对象或时区名称。 
返回
staticcreateFromTimestamp() ¶ public static
createFromTimestamp(float|int $timestamp, DateTimeZone|string|null $timezone = null): static从时间戳创建一个实例
参数
- 
                float|int$timestamp
- 要创建实例的时间戳。 
- 
                DateTimeZone|string|null$timezone optional
- 新的实例应使用的 DateTimeZone 对象或时区名称。 
返回
staticcreateInterval() ¶ 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
- 要使用的微秒数。 
返回
DateIntervaldiff() ¶ public
diff(DateTimeInterface $target, bool $absolute = false): DateInterval返回此实例与目标之间的差异。
参数
- 
                DateTimeInterface$target
- 目标实例 
- 
                bool$absolute optional
- 是否强制间隔为正数 
返回
DateIntervaldiffFiltered() ¶ 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} 
返回
intdiffForHumans() ¶ 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 等) 
返回
stringdiffFormatter() ¶ public static
diffFormatter(Cake\Chronos\DifferenceFormatterInterface|null $formatter = null): Cake\I18n\RelativeTimeFormatter获取差异格式化程序实例。
参数
- 
                Cake\Chronos\DifferenceFormatterInterface|null$formatter optional
- 差异格式化器 
返回
Cake\I18n\RelativeTimeFormatterdiffInDays() ¶ public
diffInDays(DateTimeInterface|null $other = null, bool $absolute = true): int获取天数的差异
参数
- 
                DateTimeInterface|null$other optional
- 要进行差异比较的实例。 
- 
                bool$absolute optional
- 获取差异的绝对值 
返回
intdiffInDaysFiltered() ¶ 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} 
返回
intdiffInHours() ¶ public
diffInHours(DateTimeInterface|null $other = null, bool $absolute = true): int获取小时数的差异
参数
- 
                DateTimeInterface|null$other optional
- 要进行差异比较的实例。 
- 
                bool$absolute optional
- 获取差异的绝对值 
返回
intdiffInHoursFiltered() ¶ 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} 
返回
intdiffInMinutes() ¶ public
diffInMinutes(DateTimeInterface|null $other = null, bool $absolute = true): int获取分钟数的差异
参数
- 
                DateTimeInterface|null$other optional
- 要进行差异比较的实例。 
- 
                bool$absolute optional
- 获取差异的绝对值 
返回
intdiffInMonths() ¶ public
diffInMonths(DateTimeInterface|null $other = null, bool $absolute = true): int获取月份的差异
参数
- 
                DateTimeInterface|null$other optional
- 要进行差异比较的实例。 
- 
                bool$absolute optional
- 获取差异的绝对值 
返回
intdiffInMonthsIgnoreTimezone() ¶ 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
- 获取差异的绝对值 
返回
intdiffInSeconds() ¶ public
diffInSeconds(DateTimeInterface|null $other = null, bool $absolute = true): int获取秒数的差异
参数
- 
                DateTimeInterface|null$other optional
- 要进行差异比较的实例。 
- 
                bool$absolute optional
- 获取差异的绝对值 
返回
intdiffInWeekdays() ¶ 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} 
返回
intdiffInWeekendDays() ¶ 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} 
返回
intdiffInWeeks() ¶ public
diffInWeeks(DateTimeInterface|null $other = null, bool $absolute = true): int获取星期数的差异
参数
- 
                DateTimeInterface|null$other optional
- 要进行差异比较的实例。 
- 
                bool$absolute optional
- 获取差异的绝对值 
返回
intdiffInYears() ¶ public
diffInYears(DateTimeInterface|null $other = null, bool $absolute = true): int获取年份的差异
参数
- 
                DateTimeInterface|null$other optional
- 要进行差异比较的实例。 
- 
                bool$absolute optional
- 获取差异的绝对值 
返回
intendOfDay() ¶ public
endOfDay(bool $microseconds = false): static将时间设置为 23:59:59 或 23:59:59.999999,如果 $microseconds 为真。
参数
- 
                bool$microseconds optional
- 是否设置微秒数 
返回
staticequals() ¶ public
equals(DateTimeInterface $other): bool确定实例是否等于另一个实例
参数
- 
                DateTimeInterface$other
- 要比较的实例。 
返回
boolfarthest() ¶ public
farthest(DateTimeInterface $first, DateTimeInterface $second, DateTimeInterface ...$others): static获取与实例最远的日期。
参数
- 
                DateTimeInterface$first
- 要比较的实例。 
- 
                DateTimeInterface$second
- 要比较的实例。 
- 
                DateTimeInterface...$others
- 要比较的其他实例。 
返回
staticfirstOfMonth() ¶ public
firstOfMonth(int|null $dayOfWeek = null): static修改为当前月份中给定一周中的第一天。如果没有提供 dayOfWeek,则修改为当前月份的第一天。使用提供的常量来指示所需的 dayOfWeek,例如 Chronos::MONDAY。
参数
- 
                int|null$dayOfWeek optional
- 要移动到的星期几。 
返回
staticfirstOfQuarter() ¶ public
firstOfQuarter(int|null $dayOfWeek = null): static修改为当前季度中给定一周中的第一天。如果没有提供 dayOfWeek,则修改为当前季度的第一天。使用提供的常量来指示所需的 dayOfWeek,例如 Chronos::MONDAY。
参数
- 
                int|null$dayOfWeek optional
- 要移动到的星期几。 
返回
staticfirstOfYear() ¶ public
firstOfYear(int|null $dayOfWeek = null): static修改为当前年份中给定一周中的第一天。如果没有提供 dayOfWeek,则修改为当前年份的第一天。使用提供的常量来指示所需的 dayOfWeek,例如 Chronos::MONDAY。
参数
- 
                int|null$dayOfWeek optional
- 要移动到的星期几。 
返回
staticformat() ¶ public
format(string $format): string根据 DateTimeImmutable::format() 返回格式化的日期字符串。
参数
- 
                string$format
- 字符串格式 
返回
stringfromNow() ¶ public static
fromNow(DateTimeInterface $other): DateInterval|bool获取给定时间剩余时间的便捷方法。
参数
- 
                DateTimeInterface$other
- 要获取剩余时间的日期。 
返回
DateInterval|boolgetLastErrors() ¶ public static
getLastErrors(): array|false返回最后一次 createFromFormat() 调用时的解析警告和错误。
返回与 DateTimeImmutable::getLastErrors() 相同的数据。
返回
array|falsegetTestNow() ¶ public static
getTestNow(): Cake\Chronos\Chronos|null获取创建“现在”实例时要返回的 Chronos 实例(真实或模拟)。
返回
Cake\Chronos\Chronos|nullgreaterThan() ¶ public
greaterThan(DateTimeInterface $other): bool确定实例是否大于(晚于)另一个实例
参数
- 
                DateTimeInterface$other
- 要比较的实例。 
返回
boolgreaterThanOrEquals() ¶ public
greaterThanOrEquals(DateTimeInterface $other): bool确定实例是否大于(晚于)或等于另一个实例
参数
- 
                DateTimeInterface$other
- 要比较的实例。 
返回
boolhasRelativeKeywords() ¶ public static
hasRelativeKeywords(string|null $time): bool确定时间字符串中是否包含相对关键字,用于创建相对于现在的日期以供测试实例使用。例如:下周二
参数
- 
                string|null$time
- 要检查的时间字符串。 
返回
booli18nFormat() ¶ 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|intinstance() ¶ public static
instance(DateTimeInterface $other): static从 DateTimeInterface 创建一个实例
参数
- 
                DateTimeInterface$other
- 要转换的日期时间实例。 
返回
staticisBirthday() ¶ public
isBirthday(DateTimeInterface|null $other = null): bool检查是否为生日。比较两个日期的日期/月份值。
参数
- 
                DateTimeInterface|null$other optional
- 要比较的实例,或 null 以使用当前日期。 
返回
boolisSameDay() ¶ public
isSameDay(DateTimeInterface $other): bool检查传入的日期是否与实例的当前日期相同。
参数
- 
                DateTimeInterface$other
- 要检查的实例。 
返回
boolisSameMonth() ¶ public
isSameMonth(DateTimeInterface $other): bool返回传入的日期是否与实例的月份和年份相同。
参数
- 
                DateTimeInterface$other
- 要检查的实例。 
返回
boolisSameYear() ¶ public
isSameYear(DateTimeInterface $other): bool返回传入的日期是否与实例的年份相同。
参数
- 
                DateTimeInterface$other
- 要检查的实例。 
返回
boolisWithinNext() ¶ public
isWithinNext(string|int $timeInterval): bool如果此实例将在指定的间隔内发生,则返回 true。
参数
- 
                string|int$timeInterval
- 带空格和时间类型的数值。有效类型示例:6 hours, 2 days, 1 minute。 
返回
booljsonSerialize() ¶ public
jsonSerialize(): string|int返回一个字符串,该字符串应在将此对象转换为 JSON 时进行序列化。
返回
string|intlastOfMonth() ¶ public
lastOfMonth(int|null $dayOfWeek = null): static修改为当前月内给定周日的最后一次出现。如果没有提供 dayOfWeek,则修改为当前月的最后一天。使用提供的常量来指示所需的 dayOfWeek,例如 Chronos::MONDAY。
参数
- 
                int|null$dayOfWeek optional
- 要移动到的星期几。 
返回
staticlastOfQuarter() ¶ public
lastOfQuarter(int|null $dayOfWeek = null): static修改为当前季度内给定周日的最后一次出现。如果没有提供 dayOfWeek,则修改为当前季度的最后一天。使用提供的常量来指示所需的 dayOfWeek,例如 Chronos::MONDAY。
参数
- 
                int|null$dayOfWeek optional
- 要移动到的星期几。 
返回
staticlastOfYear() ¶ public
lastOfYear(int|null $dayOfWeek = null): static修改为当前年份内给定周日的最后一次出现。如果没有提供 dayOfWeek,则修改为当前年的最后一天。使用提供的常量来指示所需的 dayOfWeek,例如 Chronos::MONDAY。
参数
- 
                int|null$dayOfWeek optional
- 要移动到的星期几。 
返回
staticlessThan() ¶ public
lessThan(DateTimeInterface $other): bool确定实例是否小于(早于)另一个实例。
参数
- 
                DateTimeInterface$other
- 要比较的实例。 
返回
boollessThanOrEquals() ¶ public
lessThanOrEquals(DateTimeInterface $other): bool确定实例是否小于(早于)或等于另一个实例。
参数
- 
                DateTimeInterface$other
- 要比较的实例。 
返回
boollistTimezones() ¶ 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以自定义缩写的包装器。
返回
arraymax() ¶ public
max(DateTimeInterface|null $other = null): static获取给定实例(默认值为现在)和当前实例之间的最大实例。
参数
- 
                DateTimeInterface|null$other optional
- 要比较的实例。 
返回
staticmin() ¶ public
min(DateTimeInterface|null $other = null): static获取给定实例(默认值为现在)和当前实例之间的最小实例。
参数
- 
                DateTimeInterface|null$other optional
- 要比较的实例。 
返回
staticmodify() ¶ public
modify(string $modifier): static根据 DateTimeImmutable::modifier() 创建一个新的日期修改后的实例。
参数
- 
                string$modifier
- 日期修饰符 
返回
static抛出
InvalidArgumentException另请参阅
next() ¶ public
next(int|null $dayOfWeek = null): static修改为给定周日的下次出现。如果没有提供 dayOfWeek,则修改为当前周日的下次出现。使用提供的常量来指示所需的 dayOfWeek,例如 Chronos::MONDAY。
参数
- 
                int|null$dayOfWeek optional
- 要移动到的星期几。 
返回
staticnice() ¶ 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) 
返回
stringnotEquals() ¶ public
notEquals(DateTimeInterface $other): bool确定实例是否不等于另一个实例。
参数
- 
                DateTimeInterface$other
- 要比较的实例。 
返回
boolnow() ¶ public static
now(DateTimeZone|string|null $timezone = null): static获取当前日期和时间的实例。
参数
- 
                DateTimeZone|string|null$timezone optional
- DateTimeZone 对象或时区名称。 
返回
staticnthOfMonth() ¶ public
nthOfMonth(int $nth, int $dayOfWeek): static|false修改为当前月内给定周日的特定出现次数。如果计算出的出现次数超出当前月的范围,则返回 false 并且不会进行任何修改。使用提供的常量来指示所需的 dayOfWeek,例如 Chronos::MONDAY。
参数
- 
                int$nth
- 要使用的偏移量。 
- 
                int$dayOfWeek
- 要移动到的星期几。 
返回
static|falsenthOfQuarter() ¶ public
nthOfQuarter(int $nth, int $dayOfWeek): static|false修改为当前季度内给定周日的特定出现次数。如果计算出的出现次数超出当前季度的范围,则返回 false 并且不会进行任何修改。使用提供的常量来指示所需的 dayOfWeek,例如 Chronos::MONDAY。
参数
- 
                int$nth
- 要使用的偏移量。 
- 
                int$dayOfWeek
- 要移动到的星期几。 
返回
static|falsenthOfYear() ¶ public
nthOfYear(int $nth, int $dayOfWeek): static|false修改为当前年份内给定周日的特定出现次数。如果计算出的出现次数超出当前年的范围,则返回 false 并且不会进行任何修改。使用提供的常量来指示所需的 dayOfWeek,例如 Chronos::MONDAY。
参数
- 
                int$nth
- 要使用的偏移量。 
- 
                int$dayOfWeek
- 要移动到的星期几。 
返回
static|falseparse() ¶ 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 对象或时区名称。 
返回
staticparseDate() ¶ 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|nullparseDateTime() ¶ 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|nullparseTime() ¶ 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|nullprevious() ¶ public
previous(int|null $dayOfWeek = null): static修改为给定周日的上一次出现。如果没有提供 dayOfWeek,则修改为当前周日的上一次出现。使用提供的常量来指示所需的 dayOfWeek,例如 Chronos::MONDAY。
参数
- 
                int|null$dayOfWeek optional
- 要移动到的星期几。 
返回
staticresetToStringFormat() ¶ public static
resetToStringFormat(): void将用于将此类型的实例转换为字符串的格式重置为默认值。
返回
voidrolloverTime() ¶ protected static
rolloverTime(int|null $value, int $max): int|null更新值为剩余值,并返回时间单位的翻转值,如果未翻转,则返回 null。
参数
- 
                int|null$value
- 时间单位值 
- 
                int$max
- 时间单位最大值 
返回
int|nullsafeCreateDateTimeZone() ¶ protected static
safeCreateDateTimeZone(DateTimeZone|string|null $object): DateTimeZone从字符串或 DateTimeZone 创建 DateTimeZone。
参数
- 
                DateTimeZone|string|null$object
- 要转换的值。 
返回
DateTimeZone抛出
InvalidArgumentExceptionsetDate() ¶ public
setDate(int $year, int $month, int $day): static设置日期。
参数
- 
                int$year
- 要设置的年份。 
- 
                int$month
- 要设置的月份。 
- 
                int$day
- 要设置的日期。 
返回
staticsetDateTime() ¶ 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 可选
- 要设置的秒数。 
返回
staticsetDefaultLocale() ¶ public static
setDefaultLocale(string|null $locale = null): void设置默认区域设置。
设置为 null 以使用 IntlDateFormatter 默认值。
参数
- 
                string|null$locale optional
- 要使用的默认区域设置字符串。 
返回
voidsetISODate() ¶ public
setISODate(int $year, int $week, int $dayOfWeek = 1): static根据 ISO 8601 标准设置日期。
参数
- 
                int$year
- 日期的年份。 
- 
                int$week
- 日期的周数。 
- 
                int$dayOfWeek 可选
- 从一周的第一天开始的偏移量。 
返回
staticsetJsonEncodeFormat() ¶ 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另请参阅
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 可选
- 用于所有未来实例的实例。 
返回
voidsetTime() ¶ public
setTime(int $hours, int $minutes, int $seconds = 0, int $microseconds = 0): static设置时间。
参数
- 
                int$hours
- 时间的时数 
- 
                int$minutes
- 时间的分钟数 
- 
                int$seconds 可选
- 时间的秒数 
- 
                int$microseconds 可选
- 时间的微秒数 
返回
staticsetTimeFromTimeString() ¶ public
setTimeFromTimeString(string $time): static通过时间字符串设置时间。
参数
- 
                string$time
- 时间字符串。 
返回
staticsetTimestamp() ¶ public
setTimestamp(int $timestamp): static根据 Unix 时间戳设置日期和时间。
参数
- 
                int$timestamp
- 表示日期的 Unix 时间戳 
返回
staticsetTimezone() ¶ public
setTimezone(DateTimeZone|string $value): static从字符串或对象设置实例的时区。
参数
- 
                DateTimeZone|string$value
- 要使用的 DateTimeZone 对象或时区名称。 
返回
staticsetToStringFormat() ¶ 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
- 格式。 
返回
voidsetWeekEndsAt() ¶ public static
setWeekEndsAt(int $day): void设置一周的最后一天
参数
- 
                int$day
- 星期结束的日期。 
返回
voidsetWeekStartsAt() ¶ public static
setWeekStartsAt(int $day): void设置一周的第一天
参数
- 
                int$day
- 星期开始的日期。 
返回
voidsetWeekendDays() ¶ public static
setWeekendDays(array $days): void设置周末
参数
- 
                array$days
- 哪些日期是“周末”。 
返回
voidstartOfWeek() ¶ public
startOfWeek(): static将日期设置为一周的第一天(在 $weekStartsAt 中定义)并将时间设置为 00:00:00
返回
staticsubMonths() ¶ public
subMonths(int $value): static从实例中删除月
与 addMonths() 具有相同的行为。
参数
- 
                int$value
- 要移除的月数。 
返回
staticsubMonthsWithOverflow() ¶ public
subMonthsWithOverflow(int $value): static在实例中添加带溢出的月份。正 $value 向前移动,负 $value 向后移动。
如果新的 ChronosDate 不存在,则天数溢出到下一个月。
示例
 (new Chronos('2012-01-30'))->addMonthsWithOverflow(1); // Results in 2013-03-01参数
- 
                int$value
- 要移除的月数。 
返回
staticsubYears() ¶ public
subYears(int $value): static从实例中删除年。
与 addYears() 具有相同的行为。
参数
- 
                int$value
- 要移除的年数。 
返回
staticsubYearsWithOverflow() ¶ public
subYearsWithOverflow(int $value): static从实例中删除带溢出的年
与 addYeasrWithOverflow() 具有相同的行为。
参数
- 
                int$value
- 要移除的年数。 
返回
statictimeAgoInWords() ¶ 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 可选
- 选项数组。 
返回
stringtoNative() ¶ public
toNative(): DateTimeImmutable返回 DateTimeImmutable 实例
此方法返回没有 Chronos 扩展的 PHP DateTimeImmutable。
返回
DateTimeImmutabletoQuarter() ¶ public
toQuarter(bool $range = false): array|int返回季度
参数
- 
                bool$range 可选
- 范围。 
返回
array|inttoRfc1036String() ¶ public
toRfc1036String(): string将实例格式化为 RFC1036
返回
string链接
toRfc1123String() ¶ public
toRfc1123String(): string将实例格式化为 RFC1123
返回
string链接
toRfc2822String() ¶ public
toRfc2822String(): string将实例格式化为 RFC2822
返回
string链接
toRfc3339String() ¶ public
toRfc3339String(): string将实例格式化为 RFC3339
返回
string链接
toRfc822String() ¶ public
toRfc822String(): string将实例格式化为 RFC822
返回
string链接
toRfc850String() ¶ public
toRfc850String(): string将实例格式化为 RFC850
返回
string链接
today() ¶ public static
today(DateTimeZone|string|null $timezone = null): static创建今天的实例
参数
- 
                DateTimeZone|string|null$timezone optional
- 要使用的时区。 
返回
statictomorrow() ¶ public static
tomorrow(DateTimeZone|string|null $timezone = null): static创建明天的实例
参数
- 
                DateTimeZone|string|null$timezone optional
- 新的实例应使用的 DateTimeZone 对象或时区名称。 
返回
staticwasWithinLast() ¶ public
wasWithinLast(string|int $timeInterval): bool如果该实例发生在指定的时间间隔内,则返回 true
参数
- 
                string|int$timeInterval
- 带空格和时间类型的数值。有效类型示例:6 hours, 2 days, 1 minute。 
返回
boolyesterday() ¶ 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$defaultLocale ¶ protected static
用于显示格式化日期字符串的默认语言环境。
请使用 static::setDefaultLocale() 和 static::getDefaultLocale() 代替。
类型
string|null$lenientParsing ¶ protected static
是否为 IntlDateFormatter 启用宽松解析。
默认为 true,这也是 IntlDateFormatter 的默认值。
类型
bool$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$testNow ¶ protected static
创建 now 实例时要返回的测试 Chronos 实例。
Chronos 提供的所有日期/时间类只有一个测试时间点。这旨在模拟对“现在”的存根,这只是一个全局的事实。
类型
Cake\Chronos\Chronos|null$wordAccuracy ¶ public static
使用 DateTime::timeAgoInWords() 格式化时间时使用的格式,差异小于 DateTime::$wordEnd
类型
array<string, string>$wordFormat ¶ public static
使用 Cake\I18n\DateTime::timeAgoInWords() 格式化时间时使用的格式,差异大于 Cake\I18n\DateTime::$wordEnd
类型
array<int>|string|int