Home > Backend Development > PHP Tutorial > $now = new DateTime;出错,奇怪了。

$now = new DateTime;出错,奇怪了。

WBOY
Release: 2016-06-23 13:57:16
Original
1068 people have browsed it

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

---
Class 'User\Action\DateTime' not found


回复讨论(解决方案)

DateTime 是 php 内置的类,不隶属于任何命名空间
如果你需要在命名空间中使用须有 \ 声明

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template