Method to wrap the setTimezone() function and set the internal time zone object.

@param   \DateTimeZone|string $tz The new DateTimeZone object.

@return  static

@since   2.1
547687
public function setTimezone($tz)
    {
        if (!$tz instanceof \DateTimeZone) {
            $tz = new \DateTimeZone($tz);
        }

        $this->tz = $tz;

        return parent::setTimezone($tz);
    }
1001876
final public static function asDateTime($input, $tz = 'UTC')
    {
        if ($input instanceof \DateTimeImmutable) {
            return $input->setTimezone(self::getTimeZone($tz));
        } elseif ($input instanceof \DateTime) {
            return self::cloneDateTime($input)->setTimezone(self::getTimeZone($tz));
        } else {
            $date = new \DateTimeImmutable($input, self::tzUtc());
            return $date->setTimezone(self::getTimeZone($tz));
        }


    }
82013
public function withTimeZone(\DateTimeZone $timezone) : self
    {
        if ($this->timezone()->getName() === $timezone->getName()) {
            return $this;
        }

        $instance = clone $this;

        $instance->date->setTimezone($timezone);

        return $instance;
    }
1136936
public function setTime($time): Timezone
    {
        if (is_string($time)) {
            $time = strtotime($time);
        }

        $this->time = $time - $this->offset;
        return $this;
    }
185949
public function setTimezone($timezone = null)
	{
		$this->date->setTimezone($timezone === null ? self::$utc : is_string($timezone) ? ($timezone === 'UTC' ? self::$utc : new \DateTimeZone($timezone)) : ($timezone instanceof \DateTimeZone ? $timezone : $timezone->getTimezone()));
		return $this;
	}
294436
function tzinfo($zone) {
		$ref=new DateTimeZone($zone);
		$loc=$ref->getLocation();
		$trn=$ref->getTransitions($now=time(),$now);
		$out=array(
			'offset'=>$ref->
				getOffset(new DateTime('now',new DateTimeZone('GMT')))/3600,
			'country'=>$loc['country_code'],
			'latitude'=>$loc['latitude'],
			'longitude'=>$loc['longitude'],
			'dst'=>$trn[0]['isdst']
		);
		unset($ref);
		return $out;
	}
228766
public function setTimezone(DateTimeZone $timezone)
    {
        if($this->_date->setTimezone($timezone) === false) {
            return false;
        }

        return $this;
    }
215073
public static function now(?string $timezone = null): DateTime
    {
        $timezone = $timezone ?: date_default_timezone_get();
        assert(Validate::isTimezone($timezone), sprintf('Invalid timezone: %s', $timezone));

        $dateTime = new DateTimeImmutable('now', new DateTimeZone($timezone));
        $year = (int) $dateTime->format('Y');
        $month = (int) $dateTime->format('n');
        $day = (int) $dateTime->format('j');
        $hour = (int) $dateTime->format('G');
        $minute = (int) $dateTime->format('i');
        $second = (int) $dateTime->format('s');

        return new static(
            Date::create($year, $month, $day),
            Time::create($hour, $minute, $second),
            Timezone::create($timezone)
        );
    }
887473
protected function getTimezoneObject($timezone) {
		if(!isset($this->timezonesObjects[$timezone])) {
			$this->timezonesObjects[$timezone] = new \DateTimezone($timezone);
		}
		return $this->timezonesObjects[$timezone];
	}
874605
public static function AdjustDateTimeToTimezoneWithTimezone( $arg, $tz )
	{
		if ( $arg instanceof Undefined )
		{
			return Undefined::getValue();
		}

	    /**
	     * @var DateTimeValue $dateTime
	     */
	    $dateTime = $arg;

		if ( $tz instanceof Undefined )
		{
		    $dt = DateTimeValue::fromDate( $dateTime->S, $dateTime->Value, false );
		    $dt->IsLocal = true;
		    return $dt;
		}

	    /**
	     * @var DayTimeDurationValue $duration
	     */
	    $duration = $tz;
		if ( $duration->getHours() > 14 || ( $duration->getHours() == 14 && ( $duration->getMinutes() > 0 || $duration->getSeconds() > 0 ) ) )
		{
			throw XPath2Exception::withErrorCodeAndParam( "FODT0003", Resources::FODT0003, $duration->ToString() );
		}

	    /**
	     * @var \DateTimeZone $dtz
	     */
	   	// Create a Timezone instance from the duration.  'R' is the sign
	    $dtz = new \DateTimeZone( $duration->Value->format( "%R%H:%I" ) );
	    try
		{
	    	if ( $dateTime->IsLocal )
	    	{
	    		$dt = new \DateTime( $dateTime->Value->format( "Y-m-d\TH:i:s" ), $dtz );
				return DateTimeValue::fromDate( $dateTime->S, $dt );
	    	}
	    	else
	    	{
	    		$dt = new \DateTime( $dateTime->Value->format( "Y-m-d\TH:i:sP" ) );
				$dt->setTimezone( $dtz );
				return DateTimeValue::fromDate( $dateTime->S, $dt );
	    	}
		}
		catch ( ArgumentException $ex )
		{
		    throw XPath2Exception::withErrorCodeAndParam( "FODT0003", Resources::FODT0003, $duration->ToString() );
		}
	}
393604
def localize(dt, tz):
    
    if not isinstance(tz, tzinfo):
        tz = pytz.timezone(tz)

    return tz.localize(dt)
700221
public void setDateTimeZone(Object dtz) throws JspTagException {
        if (dtz == null || dtz instanceof String
                && ((String) dtz).length() == 0) {
            this.dateTimeZone = null;
        } else if (dtz instanceof DateTimeZone) {
            this.dateTimeZone = (DateTimeZone) dtz;
        } else {
            try {
                this.dateTimeZone = DateTimeZone.forID((String) dtz);
            } catch (IllegalArgumentException iae) {
                this.dateTimeZone = DateTimeZone.UTC;
            }
        }
    }
1330838
public function setTimezone(\DateTimeZone $timezone = null)
    {
        if (!$timezone) {
            $timezone = $this->contactClient->getScheduleTimezone();
            if (!$timezone) {
                $timezone = $this->coreParametersHelper->getParameter(
                    'default_timezone'
                );
                $timezone = !empty($timezone) ? $timezone : date_default_timezone_get();
            }
            $timezone = new \DateTimeZone($timezone);
        }
        $this->timezone = $timezone;
        $this->now->setTimezone($timezone);

        return $this;
    }
1048934
public function setDateFromTimeStamp($timestamp, DateTimeZone $dateTimeZone) {
    $dateTimeZone = !empty($dateTimeZone) ? $dateTimeZone : new DateTimeZone('UTC');
    $this->date = new DateTime('now');
    $this->date->setTimestamp($timestamp);
    $this->date->setTimezone($dateTimeZone);
  }
29778
public void setTimeZone(final TimeZone timezone) {
        if (dates == null) {
            throw new UnsupportedOperationException(
                    "TimeZone is not applicable to current value");
        }
        this.timeZone = timezone;
        if (timezone != null) {
            if (!Value.DATE_TIME.equals(getDates().getType())) {
                throw new UnsupportedOperationException(
                        "TimeZone is not applicable to current value");
            }
            dates.setTimeZone(timezone);
            getParameters().remove(getParameter(Parameter.TZID));
            final TzId tzId = new TzId(timezone.getID());
            getParameters().replace(tzId);
        } else {
            // use setUtc() to reset timezone..
            setUtc(false);
        }
    }
567603
public R setTimezone(String timezone) {
        mBodyMap.put(BoxUser.FIELD_TIMEZONE, timezone);
        return (R) this;
    }
974038
static function dateTime(?\DateTimeZone $timezone = null): \DateTime
    {
        if (self::$now !== null) {
            $now = \DateTime::createFromFormat('U.u', sprintf('%.6F', self::$now));
            $now->setTimezone($timezone ?? new \DateTimeZone(date_default_timezone_get()));

            return $now;
        }

        return new \DateTime('now', $timezone);
    }