Return a new DateTime object, then format the date:
<?php$date=date_create("2013-03-15");echo date_format($date,"Y/m/d");?>The date_create() function returns a new DateTime object.
date_create( time,timezone);
parameter | describe |
---|---|
time | Optional. Specifies a date/time string. NULL represents the current date/time. |
timezone | Optional. Specifies the time zone for time . The default is the current time zone. Tip: See a list of all time zones supported in PHP |
Return value: | Returns a new DateTime object if successful, or FALSE if failed. |
---|---|
PHP version: | 5.2+ |
Update log: | Starting with PHP 5.3+, an exception will be thrown if an illegal date is specified. |
Returns a new DateTime object with the given time zone, then formats the date and time:
<?php$date=date_create("2013-03-15 23:40:00",timezone_open("Europe/Oslo"));echo date_format($date,"Y/m/d H:iP");? >