PHP DateTime Format Demo Page

$_SERVER Time...

$getTime = $_SERVER['REQUEST_TIME'];

Returns a UNIX EPOCH Time Stamp: 1736029680


Convert EPOCH to PHP DateTime object:
$tz_now = new DateTime("@$getTime");
the @ sign supresses errors


PHP DateTime Object / Formatting

Create a DateTime variable using "now" and a time zone Attempting to find Server Time Zone...

date_default_timezone_get() -- returned: America/Los_Angeles
ini_get('date.timezone') -- returned: America/Los_Angeles


$_timezone = date_default_timezone_get() ; // Returns current Server Time Zone

Result: $_timezone = America/Los_Angeles

$tz_now = date_create("now", timezone_open($_timezone)) ;

Formatting DateTime...

Now we can format our DateTime for display however we like:

Key To Get______________________ Format______________________ Returns:____________________
r Date-time (RFC 2822) date_format($tz_now,'r') Sat, 04 Jan 2025 14:28:00 -0800
c Date-time (ISO 8601) date_format($tz_now,'c') 2025-01-04T14:28:00-08:00
O Date-time (GMT offset) date_format($tz_now,'O') -0800
P Date-time (offset hours:minutes) date_format($tz_now,'P') -08:00
U Date-time Unix Epoch date_format($tz_now,'U') 1736029680
e timezone identifier date_format($tz_now,'e') America/Los_Angeles
T Time Zone in 3 date_format($tz_now,'T') PST
I Daylight Savings? date_format($tz_now,'I') 0
L Is it a Leap-Year? date_format($tz_now,'L') 0
-
--Mix & Match:
M/d/Y Date (Month/Day/Year) $tz_now->format('M/d/Y') Jan/04/2025
d-m-Y Date (Day-Month-Year) $tz_now->format('d-m-Y') 04-01-2025
y-m-d Date (Year-Month-Date) $tz_now->format('y-m-d') 25-01-04
Y-m-d H:i Date and Time $tz_now->format('Y-m-d H:i') 2025-01-04 14:28
-
--Each Part:
Y 4 digit Year $tz_now->format('Y') 2025
y 2 digit Year $tz_now->format('y') 25
F Month-Full Name $tz_now->format('F') January
M Month-3 Letters $tz_now->format('M') Jan
m Month-Number 01-12 $tz_now->format('m') 01
n Month-Number 1-12 $tz_now->format('n') 1
l Day-of-Week $tz_now->format('l') Saturday
D Day-of-Week in 3 $tz_now->format('D') Sat
w day 0=Sunday, 6=Saturday $tz_now->format('w') 6
z day of year 0-366 $tz_now->format('z') 3
d day number 01-31 $tz_now->format('d') 04
j day number 1-31 $tz_now->format('j') 4
H Hour - 24 $tz_now->format('H') 14
h hour - 12 $tz_now->format('h') 02
A AM PM $tz_now->format('A') PM
a am pm $tz_now->format('a') pm
i Minute $tz_now->format('i') 28
s Second $tz_now->format('s') 00
u Microsecond $tz_now->format('u') 431635