What determines (how to configure) what format string is used by php PDO driver for values of date and timestamp fields?

后端 未结 1 1313
傲寒
傲寒 2021-01-27 06:22

I have Firebird 3.0 database which have date and timestamp fields and I am using interbase extension (yes - still interbase) and Yii2 framwork in PHP 7.x. And I have Yii code:

1条回答
  •  南笙
    南笙 (楼主)
    2021-01-27 07:12

    If you are looking to confgure globally the format in Yii2, there are a few localized settings in your common config you should set:

    Config Example

    'timeZone' => 'America/New_York', // Default PHP date in Eastern.
    //... other config stuff
    'components' => [
        'formatter' => [
            'dateFormat' => 'php:Y-m-d',
            'datetimeFormat' => 'php:Y-m-d H:i:s',
            'decimalSeparator' => '.',
            'thousandSeparator' => ',',
            'defaultTimeZone' => 'UTC',       // DB Source is stored as UTC timezone.
            'timeZone' => 'America/New_York', // When formatter is used, convert to this timezone.
        ],
        //... other config stuff
      ]
    

    Time Checks

    Localized timezones can be a pain to manage, so create a page so you better understand localized formatting. See Yii2 Internationalization Docs

    select('NOW()')->scalar(Yii::$app->db);
    ?>
    
    PHP UTC dateTime (+4 Hours):
    PHP local dateTime:
    PHP local timeZone:
    Database Time Raw (expected UTC):
    Formatter -> UTC to local dateTime: formatter->asDatetime(gmdate('Y-d-m H:i:s')) ?>
    Formatter -> realtiveTime from UTC: formatter->asRelativeTime(gmdate('Y-m-d H:i:s')) ?>

    0 讨论(0)
提交回复
热议问题