MENU
Date Formatting
The characters are supported in the $format are:Day | ||
d | 01 -- 31 | Day of the month |
j | 1 -- 31 | Day of the month |
S | st, nd, rd, th | Suffix, works well with j |
z | 0 – 365 | Day of the year |
Week | ||
W | 1 – 52 | Week number of the year |
l | Sunday -- Saturday | Day of the week |
D | Mon -- Sun | Day of the week |
N | 1(Mon)—7(Sun) | Day of the week |
w | 0(Sun)—6(Sat) | Day of the week |
Month | ||
F | January – December | Month of the year |
M | Jan – Dec | Month of the year |
m | 01 -- 12 | Month of the year |
n | 1 – 12 | Month of the year |
t | 28 – 31 | No. of days in the month |
Year | ||
L | 0 – 1 | 1 if leap year, 0 otherwise |
o | 0000 – 9999 | Year, overflowing week |
Y | 0000 – 9999 | Year |
y | 00 -- 99 | Year |
Time | ||
a | am / pm | Ante or Post Meridiem |
A | AM / PM | Ante or Post Meridiem |
B | 000 – 999 | Swatch Internet time |
g | 1 – 12 | Hour |
G | 0 – 23 | Hour |
h | 01 – 12 | Hour |
H | 00 – 23 | Hour |
i | 00 – 59 | Minutes |
s | 00 – 59 | Seconds |
u | Eg. 123456 | Macroseconds |
Timezone | ||
e | Eg。UTC, GMT, Atlantis/Azores | Timezone identifier |
I | 0 – 1 | 1 if daylight saving, 0 otherwise |
O | -1200 -- +1200 | Difference to GMT |
P | -12:00 -- +12:00 | Difference to GMT |
T | Eg. EST, MDT | Timezone abbreviation |
Z | -43200 -- 50400 | Timezone offset in seconds |
Full Date and Time | ||
c | Eg. 2004-02-12 T15:30:30+00:00 | Full Date and Time |
r | Eg. Thu, 21 Dec 2000 16:01:07 +0200 | Full Date and Time |
U | Eg. 12345678 | Seconds since 1 Jan 1970 |
<!DOCTYPE html><html><head></head>
<body>
<?php
$dt = DateTime::createFromFormat('j-M-Y', '15-Mar-2014');
$dt = date_create_from_format('j-M-Y', '15-Mar-2014');
echo $dt->format("d/m/y")."<br />";
echo $dt->format("jS F Y")."<br />";
echo $dt->format("r")."<br />";
echo date_format($dt,"e T P I Z")."<br />"; // procedural
try {
$dt = new DateTime('asdfasdf');
} catch (Exception $e) {
print_r(DateTime::getLastErrors());
}
?></body></html>
15/03/14 15th March 2014 Sat, 15 Mar 2014 12:46:03 +0100 Europe/Berlin CET +01:00 0 3600 Array ( [warning_count] => 1 [warnings] => Array ( [6] => Double timezone specification ) [error_count] => 1 [errors] => Array ( [0] => The timezone could not be found in the database ) )