Database

Correct Timezone Handling

Correct Timezone Handling

Sometimes when outputting a Drupal date field, it will display in UTC, not in your desired timezone.

You can run the date through a few lines of code to output as desired.

$dt = new \DateTime($date[0]['value'], new \DateTimeZone('UTC'));
$dt->setTimeZone(new \DateTimeZone('America/Los_Angeles'));
$correct_date =  $dt->format('Y-m-d H:i:s');