本文整理汇总了PHP中HabariDateTime::last_exception方法的典型用法代码示例。如果您正苦于以下问题:PHP HabariDateTime::last_exception方法的具体用法?PHP HabariDateTime::last_exception怎么用?PHP HabariDateTime::last_exception使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HabariDateTime
的用法示例。
在下文中一共展示了HabariDateTime::last_exception方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* Helper function to create a DateTime object for the given
* time and timezone. If no time is given, defaults to 'now'. If no
* timezone given defaults to timezone set in {@link set_default_timezone()}
*
* @static
* @see DateTime::__construct()
* @param string $time String in a format accepted by
* {@link http://ca.php.net/strtotime strtotime()}, defaults to "now".
* @param string $timezone A timezone name, not an abbreviation.
* @return \Habari\DateTime
*/
public static function create($time = null, $timezone = null)
{
if ($time instanceof DateTime) {
return $time;
} elseif ($time instanceof \DateTime) {
$time = $time->format('U');
} elseif ($time === null) {
$time = 'now';
} elseif (is_numeric($time)) {
$time = '@' . $time;
}
if ($timezone === null) {
$timezone = self::$default_timezone;
}
try {
$datetime = new DateTime($time);
// passing the timezone to construct doesn't seem to do anything.
$datetime->set_timezone($timezone);
} catch (\Exception $e) {
// Do not crash if invalid data has been passed but save the exception
self::$last_exception = $e;
return false;
}
return $datetime;
}