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

C CakePHP 5.1 Chiffon API

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

命名空间

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

类时间

扩展 Chronos 提供的时间类。

添加便捷方法和区域感知格式化助手。

命名空间: Cake\I18n

常量

  • 字符串
    DEFAULT_TO_STRING_FORMAT ¶
    'H:i:s'

    用于 __toString 方法的默认格式。

  • 整数
    TICKS_PER_DAY ¶
    self::TICKS_PER_HOUR * 24
  • 整数
    TICKS_PER_HOUR ¶
    self::TICKS_PER_MINUTE * 60
  • 整数
    TICKS_PER_MICROSECOND ¶
    1
  • 整数
    TICKS_PER_MINUTE ¶
    self::TICKS_PER_SECOND * 60
  • 整数
    TICKS_PER_SECOND ¶
    1000000

属性摘要

  • $_jsonEncodeFormat protected static
    Closure|字符串|整数

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

  • $_toStringFormat protected static
    字符串|整数

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

  • $formatters protected static
    array<字符串,IntlDateFormatter>

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

  • $niceFormat public static
    字符串|整数

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

  • $ticks protected
    整数
  • $toStringFormat protected static
    字符串

    用于 __toString 方法的格式。

方法摘要

  • __construct() public

    从其他实例或从格式为 HH[:.]mm 或 HH[:.]mm[:.]ss.u 的时间字符串复制时间。

  • __toString() public

    使用设置的格式将实例格式化为字符串

  • _formatObject() protected

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

  • _parseDateTime() protected static

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

  • between() public

    返回时间是否在时间范围内。

  • endOfDay() public static

    返回设置为一天结束的实例 - 如果 $microseconds 为 true,则为 23:59:59 或 23:59:59.999999

  • equals() public

    返回时间是否等于目标时间。

  • format() public

    使用与 DateTimeImmutable::format() 相同的语法格式化字符串。

  • getHours() public

    返回时钟小时。

  • getMicroseconds() public

    返回时钟微秒。

  • getMinutes() public

    返回时钟分钟。

  • getSeconds() public

    返回时钟秒。

  • greaterThan() public

    返回时间是否大于目标时间。

  • greaterThanOrEquals() public

    返回时间是否大于或等于目标时间。

  • i18nFormat() public

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

  • jsonSerialize() public

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

  • lessThan() public

    返回时间是否小于目标时间。

  • lessThanOrEquals() public

    返回时间是否小于或等于目标时间。

  • midnight() public static

    返回设置为午夜的实例。

  • mod() protected static
  • nice() public

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

  • noon() public static

    返回设置为正午的实例。

  • now() public static

    返回设置为服务器时间的实例。

  • parse() public static

    从其他实例或从格式为 HH[:.]mm 或 HH[:.]mm[:.]ss.u 的字符串复制时间

  • parseString() protected static
  • parseTime() public static

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

  • resetToStringFormat() public static

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

  • setHours() public

    设置时钟小时。

  • setJsonEncodeFormat() public static

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

  • setMicroseconds() public

    设置时钟微秒。

  • setMinutes() public

    设置时钟分钟。

  • setSeconds() public

    设置时钟秒。

  • setTime() public

    设置时钟时间。

  • setToStringFormat() public static

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

  • toDateTimeImmutable() public

    返回设置为此时钟时间的 DateTimeImmutable 实例。

  • toNative() public

    返回设置为此时钟时间的 DateTimeImmutable 实例。

方法详细信息

__construct() ¶ public

__construct(Cake\Chronos\ChronosTimeDateTimeInterface|string|null $time = null, DateTimeZone|string|null $timezone = null)

从其他实例或从格式为 HH[:.]mm 或 HH[:.]mm[:.]ss.u 的时间字符串复制时间。

默认为服务器时间。

参数
Cake\Chronos\ChronosTimeDateTimeInterface|字符串|null $time 可选

时间

DateTimeZone|字符串|null $timezone 可选

要用于现在的时区

__toString() ¶ public

__toString(): string

使用设置的格式将实例格式化为字符串

返回
字符串

_formatObject() ¶ protected

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

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

参数
DateTimeInterface $date

日期。

array<整数>|字符串 $format

格式。

字符串|null $locale

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

返回
字符串

_parseDateTime() ¶ protected static

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

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

与 DateTime 不同,即使 $time 字符串指定了时区,返回的实例的时区也会始终转换为 $tz(如果为 null,则为默认时区)。这是 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<整数>|字符串 $format

IntlDateFormatter 接受的任何格式。

DateTimeZone|string|null $tz 可选

实例的时区

返回
static|null

between() ¶ public

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

返回时间是否在时间范围内。

参数
Cake\Chronos\ChronosTime $start

目标范围的开始时间

Cake\Chronos\ChronosTime $end

目标范围的结束时间

bool $equals 可选

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

返回
bool

endOfDay() ¶ public static

endOfDay(bool $microseconds = false): static

返回设置为一天结束的实例 - 如果 $microseconds 为 true,则为 23:59:59 或 23:59:59.999999

参数
bool $microseconds 可选

是否设置微秒

返回
static

equals() ¶ public

equals(Cake\Chronos\ChronosTime $target): bool

返回时间是否等于目标时间。

参数
Cake\Chronos\ChronosTime $target

目标时间

返回
bool

format() ¶ public

format(string $format): string

使用与 DateTimeImmutable::format() 相同的语法格式化字符串。

由于此方法使用 DateTimeImmutable::format() 格式化字符串,因此非时间格式化器将仍然被解释。请确保首先对这些字符进行转义。

参数
string $format

格式字符串

返回
字符串

getHours() ¶ public

getHours(): int

返回时钟小时。

返回
整数

getMicroseconds() ¶ public

getMicroseconds(): int

返回时钟微秒。

返回
整数

getMinutes() ¶ public

getMinutes(): int

返回时钟分钟。

返回
整数

getSeconds() ¶ public

getSeconds(): int

返回时钟秒。

返回
整数

greaterThan() ¶ public

greaterThan(Cake\Chronos\ChronosTime $target): bool

返回时间是否大于目标时间。

参数
Cake\Chronos\ChronosTime $target

目标时间

返回
bool

greaterThanOrEquals() ¶ public

greaterThanOrEquals(Cake\Chronos\ChronosTime $target): bool

返回时间是否大于或等于目标时间。

参数
Cake\Chronos\ChronosTime $target

目标时间

返回
bool

i18nFormat() ¶ public

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

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

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

示例

$time = new Time('23:10:10');
$time->i18nFormat();
$time->i18nFormat(\IntlDateFormatter::FULL);
$time->i18nFormat("HH':'mm':'ss");

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

您可以在 https://secure.php.net/manual/en/class.intldateformatter.php 中了解有关可用的 IntlDateFormatter 常量的更多信息。

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

示例

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

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

参数
string|int|null $format 可选

格式字符串。

string|null $locale 可选

应以该区域设置显示时间的名称(例如 pt-BR)

返回
字符串|整数

jsonSerialize() ¶ public

jsonSerialize(): string|int

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

返回
字符串|整数

lessThan() ¶ public

lessThan(Cake\Chronos\ChronosTime $target): bool

返回时间是否小于目标时间。

参数
Cake\Chronos\ChronosTime $target

目标时间

返回
bool

lessThanOrEquals() ¶ public

lessThanOrEquals(Cake\Chronos\ChronosTime $target): bool

返回时间是否小于或等于目标时间。

参数
Cake\Chronos\ChronosTime $target

目标时间

返回
bool

midnight() ¶ public static

midnight(): static

返回设置为午夜的实例。

返回
static

mod() ¶ protected static

mod(int $a, int $b): int
参数
int $a

右侧

int $b
返回
整数

nice() ¶ public

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

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

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

参数
string|null $locale 可选

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

返回
字符串

noon() ¶ public static

noon(): static

返回设置为正午的实例。

返回
static

now() ¶ public static

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

返回设置为服务器时间的实例。

参数
DateTimeZone|字符串|null $timezone 可选

要用于现在的时区

返回
static

parse() ¶ public static

parse(Cake\Chronos\ChronosTimeDateTimeInterface|string $time = null, DateTimeZone|string|null $timezone = null): static

从其他实例或从格式为 HH[:.]mm 或 HH[:.]mm[:.]ss.u 的字符串复制时间

默认为服务器时间。

参数
Cake\Chronos\ChronosTimeDateTimeInterface|string $time 可选

时间

DateTimeZone|字符串|null $timezone 可选

要用于现在的时区

返回
static

parseString() ¶ protected static

parseString(string $time): int
参数
string $time

格式为 HH[:.]mm 或 HH[:.]mm[:.]ss.u 的时间字符串

返回
整数

parseTime() ¶ public static

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

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

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

如果无法解析提供的時間,则返回 null。

示例

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

要解析的日期时间字符串。

string|int|null $format 可选

IntlDateFormatter 接受的任何格式。

返回
static|null

resetToStringFormat() ¶ public static

resetToStringFormat(): void

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

返回
void

setHours() ¶ public

setHours(int $hours): static

设置时钟小时。

参数
int $hours

时钟小时

返回
static

setJsonEncodeFormat() ¶ public static

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

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

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

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

参数
Closure|string|int $format

格式。

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

setMicroseconds() ¶ public

setMicroseconds(int $microseconds): static

设置时钟微秒。

参数
int $microseconds

时钟微秒

返回
static

setMinutes() ¶ public

setMinutes(int $minutes): static

设置时钟分钟。

参数
int $minutes

时钟分钟

返回
static

setSeconds() ¶ public

setSeconds(int $seconds): static

设置时钟秒。

参数
int $seconds

时钟秒

返回
static

setTime() ¶ public

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

设置时钟时间。

参数
int $hours 可选

时钟小时

int $minutes 可选

时钟分钟

int $seconds 可选

时钟秒

int $microseconds 可选

时钟微秒

返回
static

setToStringFormat() ¶ public static

setToStringFormat(string|int $format): void

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

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

参数
string|int $format

格式。

返回
void

toDateTimeImmutable() ¶ public

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

返回设置为此时钟时间的 DateTimeImmutable 实例。

参数
DateTimeZone|字符串|null $timezone 可选

DateTimeImmutable 实例所在的时区

返回
DateTimeImmutable

toNative() ¶ public

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

返回设置为此时钟时间的 DateTimeImmutable 实例。

toDateTimeImmutable() 的别名。

参数
DateTimeZone|字符串|null $timezone 可选

DateTimeImmutable 实例所在的时区

返回
DateTimeImmutable

属性详细说明

$_jsonEncodeFormat ¶ protected static

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

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

类型
Closure|字符串|整数

$_toStringFormat ¶ protected static

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

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

类型
字符串|整数

$formatters ¶ protected static

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

类型
array<字符串,IntlDateFormatter>

$niceFormat ¶ public static

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

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

类型
字符串|整数

$ticks ¶ protected

类型
整数

$toStringFormat ¶ protected static

用于 __toString 方法的格式。

类型
字符串
OpenHub
Pingping
Linode
  • 商业解决方案
  • 展示
  • 文档
  • 书籍
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 标识和商标
  • 社区
  • 参与
  • 问题 (Github)
  • 烘焙坊
  • 精选资源
  • 培训
  • 聚会
  • 我的 CakePHP
  • CakeFest
  • 时事通讯
  • 领英
  • 优酷
  • 脸书
  • 推特
  • Mastodon
  • 帮助和支持
  • 论坛
  • Stack Overflow
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API Docs 生成