PHP code example of forex-formula / yii2-jstimezonedetect

1. Go to this page and download the library: Download forex-formula/yii2-jstimezonedetect library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

forex-formula / yii2-jstimezonedetect example snippets




$timeZone = yii\jstimezonedetect\TimeZone::detect(); 

return [
    'timeZone' => $timeZone,
    'components' => [
        'formatter' => ['defaultTimeZone' => $timeZone],
        'db' => [
            'class' => 'yii\db\Connection',
            'dsn' => 'mysql:host=localhost;dbname=yii2advanced',
            'username' => 'root',
            'password' => '',
            'charset' => 'utf8',
            'on afterOpen' => function (yii\base\Event $event) {
                /* @var $db yii\db\Connection */
                $db = $event->sender;
                $db->createCommand('SET time_zone = :timeZone;', ['timeZone' => date('P')])->execute();
            }
        ]
    ]
];