本文整理匯總了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;
}