(PHP 5 >= 5.2.0)
DateTime::format -- date_format — Returns date formatted according to given format
面向对象风格
$format
)过程化风格
Returns date formatted according to given format.
object
仅为过程化风格:由 date_create() 返回的 DateTime 类型的对象。
format
Format accepted by date().
Returns the formatted date string on success 或者在失败时返回 FALSE
.
Example #1 DateTime::format() example
面向对象风格
<?php
$date = new DateTime('2000-01-01');
echo $date->format('Y-m-d H:i:s');
?>
过程化风格
<?php
$date = date_create('2000-01-01');
echo date_format($date, 'Y-m-d H:i:s');
?>
以上例程会输出:
2000-01-01 00:00:00
This method does not use locales. All output is in English.