A
A
AlexSer2020-02-27 09:05:08
PHP
AlexSer, 2020-02-27 09:05:08

How to set timezone in Crontab + Php?

Created a task in Cron to update records at exactly 6.00 AM:
0 6-8 * * * php $HOME/yii plan-robot/robot-start
In the controller

$history->date_create=date("Y-m-d H:i:s");
  $history->save();

Time in Apache2/php.ini set the Moscow zone.
But all the same, when starting the task in the database, the entry is set at 03:00:00
I understand that somewhere the time is set to GMT ... the question is what affects and how to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nokimaro, 2020-02-27
@AlexSer

When run by cron, the script is run via the CLI, which means changes to Apache2/php.ini will not be used.
Usually there is a separate cli/php.ini file, and set the zone in it.
Also, the zone can be set globally in the script itself . And of course, I agree with the answer above - it's better to use timestamp - or not to depend on local settings.
date_default_timezone_set('Europe/Moscow');
time()DateTime::getTimestamp()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question