borsaco/jalali-date-time-bundle

用于在 Symfony 应用中使用 jalali 日期时间的包

安装: 13

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

1.1.0 2020-04-17 19:25 UTC

This package is auto-updated.

Last update: 2024-09-18 05:02:56 UTC


README

用于在 Symfony 应用中使用 jalali 日期时间的包

安装

通过 Composer

composer require borsaco/jalali-date-time-bundle

编辑 app/AppKernel.php 文件,在 registerBundles() 方法中注册此包,如上所示

class AppKernel extends Kernel
{

    public function registerBundles()
    {
        $bundles = array(
            // ...
            // register the bundle here
            new Borsaco\JalaliDateTimeBundle\JalaliDateTimeBundle()
        );
    }
}

用法

在可以访问服务容器的任何地方

<?php
    // get the jlali date as a service
    $jlaliDateTime = $this->container->get('jalali_date_time');

    $jlaliDateTime->date('l j F Y H:i');
    $jlaliDateTime->date('Y-m-d', false, false);
    $jlaliDateTime->date('Y-m-d', false, false, false);
    $jlaliDateTime->date("l j F Y H:i T", false, null, null, 'America/New_York');
    
    // convert to jalali
    $unixDatetime = date("U");
    $jlaliDateTime->date('l j F Y H:i', $unixDatetime);

?>

为了使用表单类型,添加 JalaliDateType 表单类型,并使用此库创建您的视图: https://github.com/beygi/bootstrap-persian-datetimepicker