H. Ferrence H. Ferrence - 1 year ago 56
PHP Question

How to Return Proper Time Zone in PHP

I have the following PHP date function and it returns "UTC" as the timezone. I need it to return the time zone for America/New York either EST or EDT as appropriate.

date( 'D, d M Y H:i:s T' );

It returns: Thu, 08 Oct 2015 16:48:00 UTC

I need it to return Thu, 08 Oct 2015 16:48:00 EDT


Here is my complete PHP code line:

date_default_timezone_set( 'America/New_York' );
echo '<meta http-equiv="last-modified" content="' . date( 'D, d M Y H:i:s T', strtotime( get_the_date() .' ' . get_the_time() ) ) . '" />' . "\n";

It is part of a WordPress plugin whose purpose is to insert a meta tag in the head container to reflect the date and time the WP Post was last updated.

Answer Source

First defining of default time zone to America/New_York then you can use RFC850 to show the date in the desired format


This is the format for RFC850 which defines the standards for USENET messages. The PHP format is "l, d-M-y H:i:s T" and example output from date(DATE_RFC850) is "Sunday, 14-Aug-05 16:13:03 UTC".

Example of usage

$a = strtotime('2015-08-11 16:48:00');
print date(DATE_RFC850, $a);

// output
Tuesday, 11-Aug-15 16:48:00 EDT

Working demo

It is possible also to add default time zone in your php.ini

; Defines the default timezone used by the date functions
; http://php.net/date.timezone
; date.timezone =