本文整理汇总了PHP中DateTime::__construct方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTime::__construct方法的具体用法?PHP DateTime::__construct怎么用?PHP DateTime::__construct使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTime
的用法示例。
在下文中一共展示了DateTime::__construct方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct($time = 'now', \DateTimeZone $timezone = null)
{
if ($time == 'now') {
$time = self::$now;
}
parent::__construct($time, $timezone);
}
示例2: __construct
/**
* @param string $time
* @param null $timezone
*/
public function __construct($time = 'now', $timezone = null)
{
if ($time instanceof \MongoDate) {
parent::__construct(date('Y-m-d H:i:s', $time->sec), null);
return;
}
if ($time instanceof \DateTime) {
parent::__construct($time->format(self::DATE_FULL), $time->getTimezone());
return;
}
if (is_integer($time)) {
parent::__construct(date('Y-m-d H:i:s', $time), null);
return;
}
if (empty($time)) {
$time = 'now';
}
if ($timezone) {
if (!$timezone instanceof \DateTimeZone) {
$timezone = new \DateTimeZone($timezone);
}
parent::__construct($time, $timezone);
} else {
parent::__construct($time);
}
}
示例3: __construct
/**
*/
public function __construct($time = null)
{
$tz = new DateTimeZone('UTC');
try {
parent::__construct($time, $tz);
return;
} catch (Exception $e) {
}
/* Bug #5717 - Check for UT vs. UTC. */
if (substr(rtrim($time), -3) === ' UT') {
try {
parent::__construct($time . 'C', $tz);
return;
} catch (Exception $e) {
}
}
/* Bug #9847 - Catch paranthesized timezone information at end of date
* string. */
$date = preg_replace("/\\s*\\([^\\)]+\\)\\s*\$/", '', $time, -1, $i);
if ($i) {
try {
parent::__construct($date, $tz);
return;
} catch (Exception $e) {
}
}
parent::__construct('@-1', $tz);
}
示例4: __construct
public function __construct($dateValue = '', DateTimeZone $timezone = null)
{
if ($dateValue instanceof \DateTime) {
$formattedDate = $dateValue->format("Y-m-d H:i:s");
if ($formattedDate == "" || $formattedDate == self::INVALID_DATE) {
parent::__construct(self::INVALID_DATE, $timezone);
} else {
parent::__construct("now");
$this->setTimezone($dateValue->getTimezone());
$this->setDate($dateValue->format("Y"), $dateValue->format("m"), $dateValue->format("d"));
$this->setTime($dateValue->format("H"), $dateValue->format("i"), $dateValue->format("s"));
if ($timezone !== null) {
$this->setTimezone($timezone);
}
}
} elseif (is_numeric($dateValue)) {
parent::__construct("now", $timezone);
$this->setTimestamp($dateValue);
} else {
if ($dateValue == "" || $dateValue == "0000-00-00 00:00:00" || $dateValue == "0000-00-00") {
parent::__construct(self::INVALID_DATE, $timezone);
return;
}
try {
parent::__construct($dateValue, $timezone);
} catch (\Exception $er) {
parent::__construct(self::INVALID_DATE, $timezone);
return;
}
}
}
示例5: __construct
/**
* class constructor
*
* @param stdClass $p_params
* @return OdaDate $this
*/
public function __construct($p_params = NULL)
{
$params_attempt = new \stdClass();
$params_attempt->strDate = NULL;
$params_attempt->format = NULL;
$params_attempt->debug = false;
try {
$params = (object) array_merge((array) $params_attempt, (array) $p_params);
$this->_params = $params;
if (is_null($params->strDate)) {
parent::__construct();
} else {
if (is_null($params->format)) {
parent::__construct($params->strDate);
} else {
$date = \DateTime::createFromFormat($params->format, $params->strDate);
parent::__construct($date->format($params->format));
}
}
$this->_year = $this->getNumYear();
$this->_month = $this->getNumMonth();
$this->_day = $this->getNumDay();
$this->_hour = $this->getHour();
$this->_minute = $this->getMinute();
$this->_seconde = $this->getSeconde();
$this->_microseconds = $this->getMicroseconds();
return $this;
} catch (OdaException $e) {
die($e);
} catch (\Exception $e) {
die($e);
}
}
示例6: __construct
public function __construct($time = 'now', DateTimeZone $timezone = null)
{
parent::__construct($time, $timezone);
if ($time === 'now') {
$this->microTime = microtime();
}
}
示例7: __construct
public function __construct($date = null, DateTimeZone $dtz = null)
{
if ($dtz === null) {
$dtz = new DateTimeZone(date_default_timezone_get());
}
parent::__construct($date, $dtz);
}
示例8: __construct
/**
* Accepts a DateTime object or;
* Adds the ability to pass in an array or object with key names of variable
* length but a minimum of 3 characters, upper or lower case.
* See setTime and setDate for more information.
*
* @param object|array|string $time -OPTIONAL
* @param DateTimeZone $timezone -OPTIONAL
*/
public function __construct($time = 'now', $timezone = null)
{
if (!is_a($timezone, 'DateTimeZone')) {
$timezone = new DateTimeZone(date_default_timezone_get());
}
switch (gettype($time)) {
case 'object':
if (is_a($time, 'DateTime')) {
parent::__construct($time->format(self::STRING_IO_FORMAT), $time->getTimezone());
break;
}
$time = (array) $time;
case 'array':
parent::__construct('now', $timezone);
$this->setDate($time);
$this->setTime($time);
break;
case 'string':
if ($time === '') {
$time = 'now';
}
// remove AD extra data
if (substr($time, -3) === '.0Z') {
$time = substr($time, 0, 14);
}
parent::__construct($time, $timezone);
break;
case 'null':
case 'NULL':
parent::__construct('now', $timezone);
break;
default:
throw new \InvalidArgumentException('first argument is the wrong type: ' . gettype($time));
}
}
示例9: __construct
/**
* Initialize instance
*
* @param string $time
* @param string $object
*/
public function __construct($time = null, $object = null)
{
if ($time instanceof \DateTime) {
$time = $time->getTimestamp();
}
parent::__construct($time, $object);
}
示例10: __construct
public function __construct($time = 'now', \DateTimeZone $timezone = null)
{
if ((string) (int) $time === (string) $time) {
$time = '@' . $time;
}
return parent::__construct($time, $timezone);
}
示例11: __construct
/**
* @param string $time
* @param \DateTimeZone $timezone
* @throws Exception
*/
public function __construct($time = 'now', \DateTimeZone $timezone = null)
{
if (is_numeric($time)) {
throw new Exception('Invalid date format provided for DateTime: missing `@` prefix.');
}
return parent::__construct($time, $timezone);
}
示例12: __construct
public function __construct($time = 'now', DateTimeZone $timezone = null, $default_format = null)
{
if (!is_null($default_format)) {
$this->default_format = $default_format;
}
parent::__construct($time, $timezone);
}
示例13: __construct
/**
* Constructor.
*
* @param string $date String in a format accepted by strtotime(), defaults to "now".
* @param mixed $tz Time zone to be used for the date. Might be a string or a DateTimeZone object.
*/
public function __construct($date = 'now', $tz = null)
{
// Create the base GMT and server time zone objects.
if (empty(self::$gmt) || empty(self::$stz)) {
self::$gmt = new \DateTimeZone('GMT');
self::$stz = new \DateTimeZone(@date_default_timezone_get());
}
// If the time zone object is not set, attempt to build it.
if (!$tz instanceof \DateTimeZone) {
if ($tz === null) {
$tz = self::$gmt;
} elseif (is_string($tz)) {
$tz = new \DateTimeZone($tz);
}
}
// If the date is numeric assume a unix timestamp and convert it.
date_default_timezone_set('UTC');
$date = is_numeric($date) ? date('c', $date) : $date;
// Call the DateTime constructor.
parent::__construct($date, $tz);
// Reset the timezone for 3rd party libraries/extension that does not use JDate
date_default_timezone_set(self::$stz->getName());
// Set the timezone object for access later.
$this->tz = $tz;
}
示例14: __construct
public function __construct($time = 'now', DateTimeZone $timezone = null)
{
if ($timezone == null) {
$timezone = new DateTimeZone(Config::get('intl.timezone'));
}
parent::__construct($time, $timezone);
}
示例15: __construct
/**
* ISO 8601 supported. Complete date plus hours, minutes and seconds:
* <code>
* YYYY-MM-DDThh:mm:ssTZD (eg. 1997-07-16T19:20:30+01:00)
* </code>
*
* Where:
* <code>
* YYYY = four-digit year
* MM = two-digit month (01 = January, etc.)
* DD = two-digit day of month (01 through 31)
* hh = two digits of hour (00 through 23) (am/pm not allowed)
* mm = two digits of minute (00 through 59)
* ss = two digits of second (00 through 59)
* TZD = time zone designator (Z or +hh:mm or -hh:mm)
* </code>
*
*
* @see http://www.w3.org/TR/NOTE-datetime
* @see \Clock\DateTime::toIsoString()
*
* @throws \InvalidArgumentException When date and time format is wrong.
*
* @param null|string|\DateTime $dt
* @param null|\DateTimeZone $tz
*/
public function __construct($dt = null, \DateTimeZone $tz = null)
{
if (!is_null($dt)) {
if ($dt instanceof \DateTime) {
$tz = $dt->getTimezone();
$dt = $dt->format(static::ATOM);
} elseif (is_string($dt)) {
$dt = $this->normalizeDateTimeString($dt);
} elseif (is_int($dt)) {
// Timestamp.
$dt = '@' . $dt;
} elseif (is_float($dt)) {
$this->setMillisecond($this->getMillisecondsFromTimestamp($dt));
$dt = '@' . floor($dt);
} else {
throw new \InvalidArgumentException('Wrong argument type.');
}
}
try {
parent::__construct($dt, $tz);
if (is_null($dt)) {
$this->setMillisecond($this->getMillisecondsFromTimestamp(microtime(true)));
}
} catch (\Exception $exception) {
throw new \InvalidArgumentException('Wrong date and time format.', 0, $exception);
}
}