Andy Andy - 1 year ago 87
MySQL Question

Cron and SetTimeZone in PHP file

just wondering if someone could help point me in the right direction.

We have a feed, times are in UTC.

We wish to amend these times to 'Europe/London' before insertion into DB

Server is using BST (centos 6.8), PHP version 5.5

php.ini has been set in the local root to 'Europe/London'

In the php file itself, we are using

$dateTime->setTimezone(new DateTimeZone('Europe/London'));

This is working fine when I load the php file in the browser window, it's amending the time difference to Europe/London

But the cron job just ignores the SetTimezone and inserts as normal in UTC.

I have tried changing the php.ini to UTC, that still doesn't do it.

Answer Source

try to use the bellow code before runing the code in cron job.


It will set the time zone at that particular instance of code

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download