hexmedia / time-formatter-bundle
Symfony2 扩展,用于以秒为单位展示时间
v1.0.1
2013-11-20 15:40 UTC
Requires
- php: >=5.3.2
- symfony/framework-bundle: >=2.0
- twig/twig: >=1.13
This package is not auto-updated.
Last update: 2024-09-24 05:53:18 UTC
README
这是一个为 Symfony2 框架提供的 Bundle,您可以使用它轻松地将日期时间戳转换为时间的文字距离。
例如
{{ var.data|time_formatter }}
输出
day ago
Symfony2 安装
- 更新您的 composer.json
{
"require": {
"Hexmedia/TimeFormatterBundle": "dev-master"
}
}
或使用 composer 的 require 命令
composer require Hexmedia/TimeFormatterBundle:dev-master
- 更新 AppKernel
public function registerBundles() {
$bundles = array(
...
new Hexmedia\TimeFormatterBundle\HexmediaTimeFormatterBundle(),
...
);
return $bundles;
}
使用方法
要显示日期与当前日期之间的时间文字距离
{{ var.data|time_formatter }}
要显示两个自定义日期之间的时间距离,您应该使用
{{ var.data|time_formatter(message.updated) }}