Twig

灵活、快速且安全的
PHP 模板引擎

a Symfony Product
文档 过滤器 format_time
您正在阅读 Twig 3.x 的文档。切换到 Twig 1.x, 2.x 的文档。

问题与反馈

许可

Twig documentation 在新的 BSD 许可下获得许可。

format_time

format_time 过滤器格式化时间。它的行为与 format_datetime 过滤器完全相同,但不包含日期。

注意

format_time 过滤器是 IntlExtension 的一部分,默认情况下未安装。请先安装它

1
$ composer require twig/intl-extra

然后,在 Symfony 项目中,安装 twig/extra-bundle

1
$ composer require twig/extra-bundle

否则,在 Twig 环境中显式添加扩展

1
2
3
4
use Twig\Extra\Intl\IntlExtension;

$twig = new \Twig\Environment(...);
$twig->addExtension(new IntlExtension());

参数

  • locale: 区域设置代码,如 RFC 5646 中定义
  • timeFormat: 时间格式
  • pattern: 日期时间模式
  • timezone: 日期时区
  • calendar: 日历(默认为 “公历”)