eexbee / jalali-date-time-bundle
将波斯/伊朗的贾拉利(Jalali)日期时间引入到Symfony/Twig
v1.0
2020-10-16 11:39 UTC
Requires
- php: ^7.1.3
- symfony/config: ^3.4 || ^4.4 || ^5.0
- symfony/dependency-injection: ^3.4 || ^4.4 || ^5.0
- symfony/http-kernel: ^3.4 || ^4.4 || ^5.0
Requires (Dev)
- symfony/framework-bundle: ^3.4 || ^4.4 || ^5.0
- symfony/phpunit-bridge: ^3.4 || ^4.4 || ^5.0
This package is auto-updated.
Last update: 2024-09-22 03:22:31 UTC
README
将贾拉利(波斯/伊朗)日期时间引入到Symfony/Twig
要求
- symfony > 3.4
安装
composer require eexbee/jalali-date-time-bundle
使用方法
此包提供Jalali日期时间工具,可在您的控制器、Twig模板和表单中使用。
1. Twig
使用 j_datetime_format
twig过滤器将PHP DateTime对象转换为贾拉利格式
{# templates/frontend/home.html.twig #} ... {{ datetimeObject|j_datetime_format }} {# ا۲۲:۰، ۰۹ مهر ۱۳۹۹ #} ...
您还可以传递多个参数给过滤器来自定义输出。过滤器定义如下所示
... j_datetime_format( \DateTime $dateTime, //php DateTime Object $format = 'H:i ,d F Y', //Arbitrary format (checkout format table) $timeZone = 'Asia/Tehran', //Timezone $lang = 'fa' //Output number characters (fa or en) ) ...
示例
{# templates/frontend/home.html.twig #} ... {{ datetimeObject|j_datetime_format('Y-m-d H:i:s', "Europe/Paris", "en") }} {# output: 1399-07-09 12:27:49 #} ...
2. 表单
即将推出
3. 服务
由于Symfony服务管理和依赖注入机制,Jalali日期时间服务已自动准备就绪,可随时使用。