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

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

WBOY
Release: 2016-06-13 11:56:50
Original
2314 people have browsed it

$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);
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