tags:

views:

31

answers:

1

Hello,

The code returns "datesubmitted" in a nice format. The field "datesubmitted" is a timestamp of East Coast time. How could I print it out as Arizona time? Right now, that would be 3 hours behind East Coast time.

For now, I would be happy just to do that. However, during other parts of the year (when Daylight Savings time is not being used), Arizona time is only 2 hours behind East Coast time. Is there a way that I could print the date below so that Arizona time is always correctly displayed? Or would I have to change the code when Daylight Savings time stops and starts?

Thanks in advance,

John

date('l, F j, Y &\nb\sp &\nb\sp g:i a &\nb\sp &\nb\sp  \N\E\W &\nb\sp \Y\O\R\K &\nb\sp \T\I\M\E', strtotime($row["datesubmitted"]))
+1  A: 

Check out the DateTime class. Its setTimezone() method should work for you (see the examples in the User Contributed Notes). It is aware of daylight savings time. See listIdentifiers() for a list of supported time zones.

A modified example from the manual, converting today, 2pm MST to New York time:

<?php
$MSTTZ = new DateTimeZone('MST');
$ESTTZ = new DateTimeZone('America/New_York');

$dt = new DateTime('04/20/2010 2:00 pm', $MSTTZ);
var_dump($dt->format(DATE_RFC822), $dt->format('U'));
$dt->setTimezone($ESTTZ);
var_dump($dt->format(DATE_RFC822), $dt->format('U'));

/** Output:
string(29) "Tue, 20 Apr 10 14:00:00 -0600"
string(10) "1271793600"
string(29) "Tue, 20 Apr 10 16:00:00 -0400"
string(10) "1271793600"
**/
?>
Pekka