Skip to content

Instantly share code, notes, and snippets.

@SilverFire
Created October 24, 2015 09:16
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save SilverFire/6f98d2605a6574bd02f7 to your computer and use it in GitHub Desktop.
Save SilverFire/6f98d2605a6574bd02f7 to your computer and use it in GitHub Desktop.
Yii2 set timezone for DB connection
<?php
return [
'components' => [
'db' => [
'class' => '\yii\db\Connection',
'dsn' => 'mysql:host=127.0.0.1;dbname=demo',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'on afterOpen' => function($event) {
$event->sender->createCommand("SET time_zone='+00:00';")->execute();
},
],
]
]
@georgezim85
Copy link

nice, and also we can use the UTC like this:

$event->sender->createCommand("SET time_zone = 'America/Manaus'")->execute();

America/Manaus is similar to -04:00

@vc7deo
Copy link

vc7deo commented Apr 25, 2021

'America/Manaus'

i think it wont

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment