I have a custom module that displays today's date and time:
t('Today: ') . date('d F - H:i')
When I change a user's time zone on their account page the time is 'magically' outputted correctly.
How does Drupal do this?
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityThe magic comes from PHP's date_default_timezone_set()
:
Sets the default timezone used by all date/time functions in a script
Drupal uses it in
I've never seen the code itself, but it likely uses this: https://www.php.net/manual/en/datetime.settimezone.php