PHP DateTime Format Demo Page

$_SERVER Time...

$getTime = $_SERVER['REQUEST_TIME'];

Returns a UNIX EPOCH Time Stamp: 1745599261


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') Fri, 25 Apr 2025 09:41:01 -0700
c Date-time (ISO 8601) date_format($tz_now,'c') 2025-04-25T09:41:01-07:00
O Date-time (GMT offset) date_format($tz_now,'O') -0700
P Date-time (offset hours:minutes) date_format($tz_now,'P') -07:00
U Date-time Unix Epoch date_format($tz_now,'U') 1745599261
e timezone identifier date_format($tz_now,'e') America/Los_Angeles
T Time Zone in 3 date_format($tz_now,'T') PDT
I Daylight Savings? date_format($tz_now,'I') 1
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') Apr/25/2025
d-m-Y Date (Day-Month-Year) $tz_now->format('d-m-Y') 25-04-2025
y-m-d Date (Year-Month-Date) $tz_now->format('y-m-d') 25-04-25
Y-m-d H:i Date and Time $tz_now->format('Y-m-d H:i') 2025-04-25 09:41
-
--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') April
M Month-3 Letters $tz_now->format('M') Apr
m Month-Number 01-12 $tz_now->format('m') 04
n Month-Number 1-12 $tz_now->format('n') 4
l Day-of-Week $tz_now->format('l') Friday
D Day-of-Week in 3 $tz_now->format('D') Fri
w day 0=Sunday, 6=Saturday $tz_now->format('w') 5
z day of year 0-366 $tz_now->format('z') 114
d day number 01-31 $tz_now->format('d') 25
j day number 1-31 $tz_now->format('j') 25
H Hour - 24 $tz_now->format('H') 09
h hour - 12 $tz_now->format('h') 09
A AM PM $tz_now->format('A') AM
a am pm $tz_now->format('a') am
i Minute $tz_now->format('i') 41
s Second $tz_now->format('s') 01
u Microsecond $tz_now->format('u') 629299