H. Ferrence H. Ferrence - 27 days ago 11
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

Amended.

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

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

DATE_RFC850

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

date_default_timezone_set('America/New_York');
$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

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