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, 06 Nov 2009

view this page in

DateTime::format

(PHP 5 >= 5.2.0)

DateTime::formatReturns date formatted according to given format

Description

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

Parameters

object

Procedural style only: A DateTime object returned by date_create()

format

Format accepted by date().

Return Values

Returns formatted date on success or FALSE on failure.

Examples

Example #1 Displaying the date and time using the procedural form

<?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);
?>

Example #2 Displaying the date and time using the object oriented form

<?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);
?>
?>

The above example will output:

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

See Also

  • date() - Format a local time/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, 06 Nov 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites