PHP Knowledge Base

PHP time format characters

Hour

format characterExample returned valuesDescription
g1 to 1212-hour format without leading zeros
G0 to 2324-hour format without leading zeros
h01 through 1212-hour format with leading zeros
H00 through 2324-hour format with leading zeros
B000 through 999Swatch Internet time

Minutes

format characterExample returned valuesDescription
i00 to 59Minutes with leading zeros

Seconds

format characterExample returned valuesDescription
s00 through 59Seconds with leading zeros

Microseconds

format characterExample returned valuesDescription
uExample: 654321Added in PHP 5.2.2. Note that date() will always generate 000000 since it takes an integer parameter, whereas DateTime::format() does support microseconds if DateTime was created with microseconds.

Milliseconds

format characterExample returned valuesDescription
vExample: 654Added in PHP 7.0.0. Same note applies as for u.