Magento log files not showing correct timezone

Boon Chye Phang
Boon Chye Phang used Ask the Experts™
How to set the exception.log and system.log showing timezone of UTC+8?
Timezone settings in admin and web server is set to UTC+8 already, but the time logged in the files still showing UTC.
Timezone setting in Magento adminTimezone setting in web server
This is the system specification:
Magento CE
PHP 5.6.31
Windows Server 2012 R2
IIS 8.5
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Technology Scientist
First you must also change the PHP date.timezone. Change this in php.ini:

date.timezone = "Asia/Singapore"

Open in new window

Or, you can modify the PHP timezone in run-time. In run-time, you can define the timezone for mySQL as well. You can do this with a run-once script:

//run once to define timezone for both PHP and mySQL

define('TIMEZONE', 'Asia/Singapore');

$now = new DateTime();
$mins = $now->getOffset() / 60;
$sgn = ($mins < 0 ? -1 : 1);
$mins = abs($mins);
$hrs = floor($mins / 60);
$mins -= $hrs * 60;
$offset = sprintf('%+d:%02d', $hrs*$sgn, $mins);

//Your DB Connection
$db = new PDO('mysql:host=localhost;dbname=test', 'dbuser', 'dbpassword');
$db->exec("SET time_zone='$offset';");

Open in new window

Afterward, test.
NerdsOfTechTechnology Scientist

Setting timezone is the solution.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial