1 date.class.inc public BackdropDateTime::setTimezone($timezone, $force = FALSE)

Sets the time zone for the current date.

Overrides default DateTime function. Only changes output values if actually had time granularity. This should be used as a "converter" for output, to switch tzs.

In order to set a timezone for a datetime that doesn't have such granularity, merge() it with one that does.


DateTimeZone $timezone: A timezone object.

bool $force: Whether or not to skip a date with no time. Defaults to FALSE.

Return value

DateTime: This object with the timezone updated.


core/includes/date.class.inc, line 200


Extends PHP DateTime class for use with Backdrop.


public function setTimezone($timezone, $force = FALSE) {
  if (!$this->hasTime() || !$this->hasGranularity('timezone') || $force) {
    // This has no time or timezone granularity, so timezone doesn't mean
    // much. We set the timezone using the method, which will change the
    // day/hour, but then we switch back.
    $arr = $this->toArray(TRUE);
    $this->setDate($arr['year'], $arr['month'], $arr['day']);
    $this->setTime($arr['hour'], $arr['minute'], $arr['second']);
    return $this;
  return parent::setTimezone($timezone);