I did a little experiment on php DateTime class. In the documentation, they suggested syntax for creating an object of the DateTime class, as indicated.
Object Oriented Style:
public DateTime::__construct() ( [ string $time = "now" [, DateTimeZone $timezone = NULL ]] )
Procedural style:
DateTime date_create ( [ string $time = "now" [, DateTimeZone $timezone = NULL ]] )
Returns a new DateTime object.
Here is the first argument that they indicated as required, as the date / time string specified in the Date and Time Format section. Or we must pass NULL here to get the current time when using the $ timezone parameter.
But my problem is that I give the following code:
date_default_timezone_set('America/Los_Angeles'); $d_ob = new DateTime('x'); echo $d_ob->format('Ym-d');
It should throw an exception, but it repeats the current time of the date, for example -
2013-09-29
I donโt understand how it works?
source share