本文整理匯總了PHP中DateTimeInterface::getTimeZone方法的典型用法代碼示例。如果您正苦於以下問題:PHP DateTimeInterface::getTimeZone方法的具體用法?PHP DateTimeInterface::getTimeZone怎麽用?PHP DateTimeInterface::getTimeZone使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DateTimeInterface
的用法示例。
在下文中一共展示了DateTimeInterface::getTimeZone方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: validateDatePoint
/**
* Validate a DateTimeImmutable object.
*
* @param string|\DateTimeInterface $datetime
*
* @return \DateTimeImmutable
*/
protected static function validateDatePoint($datetime)
{
if ($datetime instanceof DateTimeImmutable) {
return $datetime;
}
if ($datetime instanceof DateTime) {
return new DateTimeImmutable($datetime->format(self::DATE_LOCALE), $datetime->getTimeZone());
}
return new DateTimeImmutable($datetime);
}
示例2: runsAt
public function runsAt(\DateTimeInterface $time)
{
if ($time->getTimeZone() != $this->tz) {
$time = clone $time;
$time->setTimeZone($this->tz);
}
if (!in_array($time->format('i'), $this->minutes)) {
return false;
}
if (!in_array($time->format('H'), $this->hours)) {
return false;
}
if ($this->daysOfMonth != self::LAST_DAY_OF_MONTH && !in_array($time->format('j'), $this->daysOfMonth)) {
return false;
}
if ($this->daysOfMonth == self::LAST_DAY_OF_MONTH && $time->format('j') != $time->format('t')) {
return false;
}
if (!in_array($time->format('w'), $this->daysOfWeek)) {
return false;
}
if (!in_array($time->format('n'), $this->months)) {
return false;
}
return true;
}