本文整理汇总了PHP中DateTime::get方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTime::get方法的具体用法?PHP DateTime::get怎么用?PHP DateTime::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTime
的用法示例。
在下文中一共展示了DateTime::get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getVersionPreview
/**
* @see Object\ClassDefinition\Data::getVersionPreview
* @param \Zend_Date|\DateTime $data
* @param null|Object\AbstractObject $object
* @param mixed $params
* @return string
*/
public function getVersionPreview($data, $object = null, $params = [])
{
if ($data instanceof \Zend_Date) {
return $data->get(\Zend_Date::DATE_MEDIUM);
} elseif ($data instanceof \DateTimeInterface) {
return $data->format("Y-m-d");
}
}
示例2: toLdapDateTime
/**
* Converts a date-entity to an LDAP-compatible date-string
*
* The date-entity <var>$date</var> can be either a timestamp, a
* DateTime Object, a string that is parseable by strtotime() or a Zend_Date
* Object.
*
* @param integer|string|DateTimt|Zend_Date $date The date-entity
* @param boolean $asUtc Whether to return the LDAP-compatible date-string
* as UTC or as local value
* @return string
* @throws InvalidArgumentException
*/
public static function toLdapDateTime($date, $asUtc = true)
{
if (!$date instanceof DateTime) {
if (is_int($date)) {
$date = new DateTime('@' . $date);
$date->setTimezone(new DateTimeZone(date_default_timezone_get()));
} else {
if (is_string($date)) {
$date = new DateTime($date);
} else {
if ($date instanceof Zend_Date) {
$date = new DateTime($date->get(Zend_Date::ISO_8601));
} else {
throw new InvalidArgumentException('Parameter $date is not of the expected type');
}
}
}
}
$timezone = $date->format('O');
if (true === $asUtc) {
$date->setTimezone(new DateTimeZone('UTC'));
$timezone = 'Z';
}
if ('+0000' === $timezone) {
$timezone = 'Z';
}
return $date->format('YmdHis') . $timezone;
}
示例3: setUp
/**
* Sets up the fixture, for example, open a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->dateTime = DateTime::get()->setTimestamp('1432674145')->setTimezone(new \DateTimeZone('Europe/London'));
}