Time::format()

Returns the date/time formatted according to the given format.

Table of Contents
  1. Description
  2. Example
  3. Formats

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().

FormatDescriptionExample
dDay of the month, 2 digits with leading zeros.01 to 31
DA textual representation of a day, three letters.Mon through Sun
jDay of the month without leading zeros.1 to 31
lA full textual representation of the day of the week.Sunday through Saturday
FA full textual representation of a month.January through December
mNumeric representation of a month, with leading zeros.01 through 12
MA short textual representation of a month, three letters.Jan through Dec
nNumeric representation of a month, without leading zeros.1 through 12
tNumber of days in the given month.28 through 31
YA full numeric representation of a year, 4 digits.1999 or 2003
yA two digit representation of a year.99 or 03
aLowercase ‘ante meridiem’ and ‘post meridiem’.am or pm
AUppercase ‘ante meridiem’ and ‘post meridiem’.AM or PM
g12-hour format of an hour without leading zeros.1 through 12
G24-hour format of an hour without leading zeros.0 through 23
h12-hour format of an hour with leading zeros.01 through 12
H24-hour format of an hour with leading zeros.00 through 23
iMinutes with leading zeros.00 to 59
sSeconds, with leading zeros.00 through 59
uMicroseconds.654321
vMilliseconds.654
cISO 8601 date.2004-02-12T15:19:21+00:00
rRFC 2822 formatted date.Thu, 21 Dec 2000 16:01:07 +0200
USeconds since the Unix Epoch (January 1 1970 00:00:00 GMT).1670471338

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::i()

Returns the date/time formatted according to the given pattern.

Time::name()

Returns the date/time format as a valid file name.

Time::to()

Converts current date/time zone to other date/time zone.