CakePHP
  • 文档
    • 手册
    • API
    • 视频
    • 报告安全问题
    • 隐私政策
    • 标志和商标
  • 商业解决方案
  • 周边产品
  • 公路旅行
  • 团队
  • 社区
    • 社区
    • 参与进来
    • 问题(Github)
    • 烘焙坊
    • 精选资源
    • 培训
    • 聚会
    • 我的 CakePHP
    • CakeFest
    • 时事通讯
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • 帮助和支持
    • 论坛
    • Stack Overflow
    • IRC
    • Slack
    • 付费支持
CakePHP

C CakePHP 5.1 Chiffon API

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

命名空间

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

类 RelativeTimeFormatter

用于格式化相对日期和时间的辅助类。

命名空间: Cake\I18n

方法摘要

  • _diffData() protected

    计算格式化相对差值字符串所需的数据。

  • _options() protected

    构建用于相对日期格式化的选项。

  • dateAgoInWords() public

    将日期格式化为相对日期字符串。

  • diffForHumans() public

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

  • timeAgoInWords() public

    将日期格式化为相对时间字符串。

方法详情

_diffData() ¶ protected

_diffData(string|int $futureTime, string|int $pastTime, bool $backwards, array<string, mixed> $options): array

计算格式化相对差值字符串所需的数据。

参数
string|int $futureTime

未来的时间戳。

string|int $pastTime

过去的时间戳。

bool $backwards

差异是否为反向。

array<string, mixed> $options

选项数组。

返回
array

_options() ¶ protected

_options(array<string, mixed> $options, string $class): array<string, mixed>

构建用于相对日期格式化的选项。

参数
array<string, mixed> $options

用户提供的选项。

string $class

用于默认值的类名。

返回
array<string, mixed>

dateAgoInWords() ¶ public

dateAgoInWords(Cake\I18n\DateTimeCake\I18n\Date $date, array<string, mixed> $options = []): string

将日期格式化为相对日期字符串。

参数
Cake\I18n\DateTimeCake\I18n\Date $date

要格式化的日期。

array<string, mixed> $options optional

选项数组。

返回
string
另请参阅
\Cake\I18n\Date::timeAgoInWords()

diffForHumans() ¶ public

diffForHumans(Cake\Chronos\ChronosDateDateTimeInterface $first, Cake\Chronos\ChronosDateDateTimeInterface|null $second = null, bool $absolute = false): string

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

参数
Cake\Chronos\ChronosDateDateTimeInterface $first

要开始的日期时间。

Cake\Chronos\ChronosDateDateTimeInterface|null $second optional

要比较的日期时间。

bool $absolute optional

移除时间差修饰符 ago、after 等。

返回
string
另请参阅
\Cake\Chronos\Chronos::diffForHumans

timeAgoInWords() ¶ public

timeAgoInWords(Cake\I18n\DateTimeCake\I18n\Date $time, array<string, mixed> $options = []): string

将日期格式化为相对时间字符串。

参数
Cake\I18n\DateTimeCake\I18n\Date $time

要格式化的时间实例。

array<string, mixed> $options optional

选项数组。

返回
string
另请参阅
\Cake\I18n\Time::timeAgoInWords()
OpenHub
Pingping
Linode
  • 商业解决方案
  • 展示
  • 文档
  • 手册
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 标志和商标
  • 社区
  • 参与进来
  • 问题(Github)
  • 烘焙坊
  • 精选资源
  • 培训
  • 聚会
  • 我的 CakePHP
  • CakeFest
  • 时事通讯
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • 帮助和支持
  • 论坛
  • Stack Overflow
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API 文档 生成