downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

DateTime::getLastErrors> <DateTime::diff
Last updated: Fri, 13 Nov 2009

view this page in

DateTime::format

(PHP 5 >= 5.2.0)

DateTime::format指定した書式でフォーマットした日付を返す

説明

public string DateTime::format ( string $format )
string date_format ( DateTime $object , string $format )

パラメータ

object

手続き型のみ: date_create() が返す DateTime オブジェクト

format

date() が理解できる書式指定文字列。

返り値

成功した場合にフォーマット済みの日付、失敗した場合に FALSE を返します。

例1 手続き型での日付と時刻の表示

<?php
date_default_timezone_set
('Europe/London');

$datetime date_create('2008-08-03 14:52:10');
echo 
date_format($datetime'jS, F Y') . "\n";
echo 
date_format($datetimeDATE_ATOM);
?>

例2 オブジェクト指向型での日付と時刻の表示

<?php
date_default_timezone_set
('Europe/London');

$datetime = new DateTime('2008-08-03 14:52:10');
echo 
$datetime->format('jS, F Y') . "\n";
echo 
$datetime->format(DATE_ATOM);
?>
?>

上の例の出力は以下となります。

3rd, August 2008
2008-08-03T14:52:10+01:00

参考

  • date() - ローカルの日付/時刻を書式化する



add a note add a note User Contributed Notes
DateTime::format
There are no user contributed notes for this page.

DateTime::getLastErrors> <DateTime::diff
Last updated: Fri, 13 Nov 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites