Brings Jalali (Persian/Iranian) DateTime to Symfony/Twig
- symfony > 3.4
composer require eexbee/jalali-date-time-bundle
This bundle provides Jalali DateTime tools to be used inside your Controllers, Twig templates and forms.
Use j_datetime_format
twig filter to convert php DateTime object into Jalali format
{# templates/frontend/home.html.twig #}
...
{{ datetimeObject|j_datetime_format }} {# ا۲۲:۰، ۰۹ مهر ۱۳۹۹ #}
...
You can Also pass several parameters to the filter to customize the output. Filter definition looks like this:
...
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)
)
...
Example:
{# 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 #}
...
soon
Jalali DateTime service is automatically ready to use due to the symfony service management and dependency injection mechanism.