Time::format()
Returns the date/time formatted according to the given format.
Table of Contents
Description
Time::format(string $format = 'Y-m-d H:i:s'): string;This method returns the date/time formatted according to the given format.
Example
$time = new Time;
echo $time->format('c'); // Returns `'2026-02-03T07:25:50+07:00'`Formats
The following is a list of date/time formats that you will probably use frequently. You can read the complete list of it on the official documentation of DateTime::format().
| Format | Description | Example |
|---|---|---|
d | Day of the month, 2 digits with leading zeros. | 01 to 31 |
D | A textual representation of a day, three letters. | Mon through Sun |
j | Day of the month without leading zeros. | 1 to 31 |
l | A full textual representation of the day of the week. | Sunday through Saturday |
F | A full textual representation of a month. | January through December |
m | Numeric representation of a month, with leading zeros. | 01 through 12 |
M | A short textual representation of a month, three letters. | Jan through Dec |
n | Numeric representation of a month, without leading zeros. | 1 through 12 |
t | Number of days in the given month. | 28 through 31 |
Y | A full numeric representation of a year, 4 digits. | 1999 or 2003 |
y | A two digit representation of a year. | 99 or 03 |
a | Lowercase ‘ante meridiem’ and ‘post meridiem’. | am or pm |
A | Uppercase ‘ante meridiem’ and ‘post meridiem’. | AM or PM |
g | 12-hour format of an hour without leading zeros. | 1 through 12 |
G | 24-hour format of an hour without leading zeros. | 0 through 23 |
h | 12-hour format of an hour with leading zeros. | 01 through 12 |
H | 24-hour format of an hour with leading zeros. | 00 through 23 |
i | Minutes with leading zeros. | 00 to 59 |
s | Seconds, with leading zeros. | 00 through 59 |
u | Microseconds. | 654321 |
v | Milliseconds. | 654 |
c | ISO 8601 date. | 2004-02-12T15:19:21+00:00 |
r | RFC 2822 formatted date. | Thu, 21 Dec 2000 16:01:07 +0200 |
U | Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT). | 1670471338 |
Time::_()
The dynamic method initiator.
Time::__call()
Proxy for missing methods.
Time::__callStatic()
Proxy for missing static methods.
Time::__construct()
The constructor.
Time::__get()
Proxy for missing properties.
Time::__invoke()
Proxy for the current object, called as a function.
Time::__serialize()
Provides data to be serialized.
Time::__toString()
Proxy for the current object, casted as a string.
Time::__unserialize()
Converts the serialized data back to its object.
Time::date()
Returns the day of the month.
Time::day()
Returns the day number of the week, or the day name.
Time::format()
Returns the date/time formatted according to the given format.
Time::from()
Object instantiator.
Time::hour()
Returns the hour number.
Time::i()
Returns the date/time formatted according to the given pattern.
Time::minute()
Returns the minute number.
Time::month()
Returns the month number, or the month name.
Time::name()
Returns the date/time format as a valid file name.
Time::second()
Returns the second number.
Time::to()
Converts current date/time zone to other date/time zone.
Time::year()
Returns the year number.