Home  >  Article  >  Backend Development  >  $now = new DateTime;报错,奇怪了

$now = new DateTime;报错,奇怪了

WBOY
WBOYOriginal
2016-06-13 11:56:502297browse

$now = new DateTime;出错,奇怪了。
在使用命名空间时下面语句显示没有找到:
$now   = new DateTime;出错

---
Class 'User\Action\DateTime' not found
------解决方案--------------------
DateTime 是 php 内置的类,不隶属于任何命名空间
如果你需要在命名空间中使用须有 \ 声明

<?php<br />namespace User\Action;<br />$now   = new \DateTime;<br />print_r($now);
DateTime Object
(
    [date] => 2014-05-11 15:43:30
    [timezone_type] => 3
    [timezone] => Asia/Shanghai
)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn