I am running solr 7.7.x which imports data including dates from MySQL. In the DB the time is saved to the servers current time zone. After solr imports, it converts to UTC. This leads to a shift of 2h in my case when pulling the data:
MySQL:
"date_created":"2019-04-01 17:18:45"
MySQL import query:
SELECT DATE_FORMAT( c.date_created, '%Y-%m-%dT%H:%i:%sZ' ) AS date_created FROM cls
solr:
"date_created":"2019-04-01T19:18:45Z",
PHP:
date("Y-m-d H:i:s", strtotime($item['date_created']));
I also tried:
$tz = new DateTimeZone('Europe/Berlin');
$date = new DateTime($classified['date_created']);
$date->setTimezone($tz);
$ad['time_created'][$index] = $date->format('Y-m-d H:i:s');
Same result, the time is offset by 2 hours. If I change the DateTimeZone to US, it will offset bei 9h, which shows that at least it has some effect.
I temporarily fixed it by: $ad['time_created'][$index] = date("Y-m-d H:i:s", strtotime($classified['date_created'])-7200);
which does not look like a good solution to me.
How can I keep the time from MySQL and what is the recommened approach to deal with timezones in solr?