本文整理汇总了PHP中DateTimeInterface::getTimezone方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeInterface::getTimezone方法的具体用法?PHP DateTimeInterface::getTimezone怎么用?PHP DateTimeInterface::getTimezone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTimeInterface
的用法示例。
在下文中一共展示了DateTimeInterface::getTimezone方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct(\DateTimeInterface $date = NULL)
{
if ($date === NULL) {
$this->date = new \DateTimeImmutable();
} else {
$this->date = new \DateTimeImmutable('@' . $date->getTimestamp(), $date->getTimezone());
}
}
示例2: init
/**
* Init.
*
* @param TwitterMessageId $id
* @param TwitterUser $sender
* @param string $text
* @param TwitterEntities $entities
* @param \DateTimeInterface $date
*/
public function init(TwitterMessageId $id, TwitterUser $sender, $text, TwitterEntities $entities, \DateTimeInterface $date)
{
Assertion::eq(new \DateTimeZone('UTC'), $date->getTimezone());
$this->entities = $entities;
$this->id = $id;
$this->sender = $sender;
$this->text = $text;
$this->date = $date;
}
示例3: monday
public static function monday(\DateTimeInterface $date = null)
{
if ($date) {
$today = DateTime::createFromFormat('U', $date->format('U'), $date->getTimezone())->asDate()->asDateTime();
} else {
$today = self::today();
}
if ($today->format('w') < 1) {
$monday = $today->modify('-6 day');
} else {
$monday = $today->modify('-' . ($today->format('w') - 1) . ' day');
}
return $monday;
}
示例4: computeExpires
protected function computeExpires(\DateTimeInterface $expires = NULL)
{
// TODO: Lock min / max timeouts must be configurable.
$min = new \DateTimeImmutable('+2 minutes');
if ($expires === NULL || $expires < $min) {
return $min;
}
$max = new \DateTimeImmutable('+2 hours');
if ($expires > $max) {
return $max;
}
return new \DateTimeImmutable('@' . $expires->getTimestamp(), $expires->getTimezone());
}
示例5: extractTimezone
/**
* @param \DateTimeInterface $dateTime
*
* @return string
*/
private function extractTimezone(\DateTimeInterface $dateTime)
{
return $dateTime->getTimezone()->getName();
}
示例6: formatDateTime
/**
* @param \DateTimeInterface $date
* @param int $dateType
* @param int $timeType
* @param null $locale
* @param null $timezone
* @param string|null $pattern
* @return string
*/
public function formatDateTime(
\DateTimeInterface $date,
$dateType = \IntlDateFormatter::SHORT,
$timeType = \IntlDateFormatter::SHORT,
$locale = null,
$timezone = null,
$pattern = null
) {
$formatter = new \IntlDateFormatter(
$locale ?: $this->_localeResolver->getLocale(),
$dateType,
$timeType,
$timezone ?: $date->getTimezone(),
null,
$pattern
);
return $formatter->format($date);
}
示例7: formatDateTime
/**
* @param \DateTimeInterface $date
* @param int $dateType
* @param int $timeType
* @param null $locale
* @param null $timezone
* @param string|null $pattern
* @return string
*/
public function formatDateTime(\DateTimeInterface $date, $dateType = \IntlDateFormatter::SHORT, $timeType = \IntlDateFormatter::SHORT, $locale = null, $timezone = null, $pattern = null)
{
if ($timezone === null) {
if ($date->getTimezone() === null || $date->getTimezone()->getName() === '+00:00') {
$timezone = new \DateTimeZone('UTC');
} else {
$timezone = $date->getTimezone();
}
}
$formatter = new \IntlDateFormatter($locale ?: $this->_localeResolver->getLocale(), $dateType, $timeType, $timezone, null, $pattern);
return $formatter->format($date);
}
示例8: date_timezone_get
function date_timezone_get(DateTimeInterface $datetime)
{
return $datetime->getTimezone();
}
示例9: setExpires
public function setExpires(\DateTimeInterface $expires)
{
$this->expires = new \DateTimeImmutable('@' . $expires->getTimestamp(), $expires->getTimezone());
}
示例10: setEnd
/**
* Set the end date for the range
*
* @param \DateTimeInterface $end
* @return DateRange
*/
public function setEnd(\DateTimeInterface $end)
{
$this->endTimezone = $end->getTimezone();
$this->end = (new \DateTimeImmutable($end->format('c')))->setTimezone(new \DateTimeZone('UTC'));
return $this;
}
示例11: createFormatter
/**
* @param \DateTimeInterface $dateTime
* @param int $dateType
* @param int $timeType
* @param string $pattern
*
* @return \IntlDateFormatter
*/
private function createFormatter($dateTime, $dateType = self::NONE, $timeType = self::NONE, $pattern = null)
{
return new \IntlDateFormatter($this->locale, $dateType, $timeType, $dateTime->getTimezone(), \IntlDateFormatter::GREGORIAN, $pattern);
}
示例12: expiresAt
/**
* Sets the expiration time for this cache item.
*
* @param \DateTimeInterface $expiration
* The point in time after which the item MUST be considered expired.
* If null is passed explicitly, a default value MAY be used. If none is set,
* the value should be stored permanently or for as long as the
* implementation allows.
*
* @return static
* The called object.
*/
public function expiresAt($expiration)
{
$now = new \DateTime('now', $expiration->getTimezone());
$this->cacheLifetime = $expiration->getTimestamp() - $now->getTimestamp();
return $this;
}