开发者

php 101 DateTime using atom format

开发者 https://www.devze.com 2023-03-17 00:44 出处:网络
I\'m trying to use the DateTime class to output the current time in DateTime::ATOM format. I\'m not sure if I\'m even using it correctly. Or do 开发者_如何学CI have to import a library or maybe turn

I'm trying to use the DateTime class to output the current time in DateTime::ATOM format.

I'm not sure if I'm even using it correctly. Or do 开发者_如何学CI have to import a library or maybe turn on a wamp php module.

I'm getting "syntax error, unexpected T_NEW" error

here is the code:

<?php
function d()
{

     $df =  new DateTime(DateTime::ATOM);
    echo $df;
}

?>


You'd use DateTime like this:

$time = new DateTime;
echo $time->format(DateTime::ATOM);

The constructor (new DateTime) expects the time you want to create the object for, the format doesn't matter at this point. You specify the format when outputting the time.

Having said that, the error you're getting seems pretty unrelated and may not have anything to do with that specific line.


Use :

 $x = date(DATE_ATOM, strtotime('2009-11-04T19:55:41Z'));

or

 $x = date(DATE_ATOM, mktime(0, 0, 0, 7, 1, 2000));
0

精彩评论

暂无评论...
验证码 换一张
取 消