Jump to content

Brendan Kidwell

Members
  • Posts

    2
  • Joined

  • Last visited

Everything posted by Brendan Kidwell

  1. This works better for me, and accounts for daylight savings time switches -- it looks at PHP's timezone offset for the current date and time in the current timezone: // Add these lines to your config.php file. // Tell PHP to use this timezone as the default when a timezone API call doesn't specify a zone. // Change to your local time zone name: https://www.php.net/manual/en/timezones.php date_default_timezone_set('America/New_York'); // Initialize database connection with session time zone based on PHP's time zone. $dbTimeZone = (function() { // What is the timezone offset (in minutes) from UTC for the current time in the current timezone? $minutes = (new \DateTime())->getOffset() / 60; $sign = ($minutes >= 0) ? '+' : ''; $h = str_pad(intdiv($minutes, 60), 2, '0'); $m = str_pad($minutes % 60, 2, '0'); return $sign . $h . ':' . $m; })(); $config->dbInitCommand = "SET NAMES '{charset}', time_zone = '$dbTimeZone' "; // Tell ProcessWire to use this timezone. // (You'll find this in your config file already under the comment "Installer: Time zone setting".) $config->timezone = 'America/New_York'; I checked it and I see that the actual timestamps being recorded in the database are in UTC timezone, as they should be. They get formatted with the correct LOCAL timezone offset when displayed in the admin screens.
×
×
  • Create New...