Php 101 DateTime using atom format

I am trying to use the DateTime class to display the current time in DateTime :: ATOM format.

I am not sure if I use it correctly. Or do I need to import a library or maybe turn on the wamp php module.

I get the error "Syntax error, unexpected error T_NEW"

here is the code:

<?php function d() { $df = new DateTime(DateTime::ATOM); echo $df; } 

? >

+6
source share
2 answers

You would use DateTime as follows:

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

The constructor ( new DateTime ) expects the time during which you want to create the object; the format does not matter at the moment. You specify the format for time output.

Having said that, the error you get seems rather unrelated and may have nothing to do with this particular line.

+7
source

Using:

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

or

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

Source: https://habr.com/ru/post/891858/


All Articles