本文整理汇总了PHP中DateTimeZone::__construct方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeZone::__construct方法的具体用法?PHP DateTimeZone::__construct怎么用?PHP DateTimeZone::__construct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTimeZone
的用法示例。
在下文中一共展示了DateTimeZone::__construct方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor.
*
* @param string|DateTimeZone|PHPDateTimeZone|null $timezone [optional] The timezone as a string, or as
* DateTimeZone or PHPDateTimeZone instance. Null to use the default timezone.
*
* @throws Exception Throws an exception on failure.
*/
public function __construct($timezone)
{
// Parse null
if ($timezone === null) {
$timezone = DateTimeZoneUtils::getDefaultTimezone();
} else {
if ($timezone instanceof DateTime) {
$timezone = $timezone->getTimezone();
} else {
if ($timezone instanceof PHPDateTime) {
$timezone = $timezone->getTimezone();
}
}
}
// Parse DateTimeZone and PHPDateTimeZone instances
if ($timezone instanceof parent) {
parent::__construct($timezone->getName());
return $this;
}
// Check if this is a valid timezone ID
if (DateTimeZoneUtils::isValidTimezoneId($timezone)) {
parent::__construct($timezone);
return $this;
}
// Invalid timezone, throw an exception
throw new Exception('Invalid timezone (\'' . $timezone . '\' was given)');
}
示例2: __construct
/**
* Initializes the {@link $name} property.
*
* @param string $timezone
*/
public function __construct($timezone)
{
parent::__construct($timezone);
$name = $this->getName();
if ($name == 'utc') {
$name = 'UTC';
}
$this->name = $name;
}
示例3: __construct
/**
* CONSTRUCTOR
* Build a new DateTimeZone object.
* Store user timezone identifier in session.
*
* @since 0.0.1
*
* @see getTimeZone()
*
* @access public
* @param string|null $timezone Optional. Timezone identifier to use. Default: null
* @return void
*/
public function __construct($timezone = null)
{
if (null === $timezone) {
$timezone = self::getTimeZone();
}
// Store timezone in session
$_SESSION['timezone'] = $timezone;
parent::__construct($timezone);
}
示例4: __construct
public function __construct($in_dtz = null)
{
$this->tz_defined = false;
if (!isset($in_dtz)) {
return;
}
$olson = olson_from_tzstring($in_dtz);
if (isset($olson)) {
try {
parent::__construct($olson);
$this->tz_defined = $olson;
} catch (Exception $e) {
dbg_error_log('ERROR', 'Could not handle timezone "%s" (%s) - will use floating time', $in_dtz, $olson);
parent::__construct('UTC');
$this->tz_defined = false;
}
} else {
dbg_error_log('ERROR', 'Could not recognize timezone "%s" - will use floating time', $in_dtz);
parent::__construct('UTC');
$this->tz_defined = false;
}
}