这篇“php中的DateTime有什么作用”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“php中的DateTime有什么作用”文章吧。
说明
1、DateTime对象可以过程化地写出来的。
2、提供了一种getLastErrors()方法,但是当使用面向对象的方法时,DateTime对象会以异常的形式被抛出。
实例
$date = date_create('asdfasdf');
print_r(DateTime::getLastErrors());
// Array
// (
// [warning_count] => 1
// [warnings] => Array
// (
// [6] => Double timezone specification
// )
// [error_count] => 1
// [errors] => Array
// (
// [0] => The timezone could not be found in the database
// )
// )
try {
$date = new DateTime('asdfasdf');
} catch (Exception $e) {
echo $e->getMessage(), PHP_EOL;
}
// DateTime::__construct(): Failed to parse time string (asdfasdf) at position 0 (a): The timezone could not be found in the database
以上就是关于“php中的DateTime有什么作用”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注天达云行业资讯频道。