本文整理汇总了PHP中QDateTime::setTimezone方法的典型用法代码示例。如果您正苦于以下问题:PHP QDateTime::setTimezone方法的具体用法?PHP QDateTime::setTimezone怎么用?PHP QDateTime::setTimezone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDateTime
的用法示例。
在下文中一共展示了QDateTime::setTimezone方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setTime
/**
* Sets the time portion to the given time. If a QDateTime is given, will use the time portion of that object.
* Works around a problem in php that if you set the time across a daylight savings time boundary, the timezone
* does not advance. This version will detect that and advance the timezone.
*
* @param int|QDateTime $mixValue
* @param int|null $intMinute
* @param int|null $intSecond
* @return QDateTime
*/
public function setTime($mixValue, $intMinute = null, $intSecond = null)
{
if ($mixValue instanceof QDateTime) {
if ($mixValue->IsTimeNull()) {
$this->blnTimeNull = true;
$this->ReinforceNullProperties();
return $this;
}
// normalize the timezones
$tz = $this->getTimezone();
if ($tz && in_array($tz->getName(), timezone_identifiers_list())) {
// php limits you to ID only timezones here, so make sure we have one of those
$mixValue->setTimezone($tz);
}
$intHour = $mixValue->Hour;
$intMinute = $mixValue->Minute;
$intSecond = $mixValue->Second;
} else {
$intHour = $mixValue;
}
// If HOUR or MINUTE is NULL...
if (is_null($intHour) || is_null($intMinute)) {
parent::setTime($intHour, $intMinute, $intSecond);
$this->blnTimeNull = true;
$this->ReinforceNullProperties();
return $this;
}
$intHour = QType::Cast($intHour, QType::Integer);
$intMinute = QType::Cast($intMinute, QType::Integer);
$intSecond = QType::Cast($intSecond, QType::Integer);
$this->blnTimeNull = false;
/*
// Possible fix for a PHP problem. Can't reproduce, so leaving code here just in case it comes back.
// The problem is with setting times across dst barriers
if ($this->Hour == 0 && preg_match('/[0-9]+/', $this->getTimezone()->getName())) {
// fix a php problem with GMT and relative timezones
$s = 'PT' . $intHour . 'H' . $intMinute . 'M' . $intSecond . 'S';
$this->add (new DateInterval ($s));
// will continue and set again to make sure, because boundary crossing will change the time
}*/
parent::setTime($intHour, $intMinute, $intSecond);
return $this;
}