|
Posted by Jerry Stuckle on December 4, 2008, 4:22 pm
Please log in for more thread options Justin Voelker wrote:
>> Justin Voelker wrote:
>>> Hello everyone:
>>> I have seen posts like this one a couple times looking through this
>>> group but I have yet to find a simple, elegant answer and I know there
>>> must be one. I have a mysql database that has a datetime field in the
>>> format Y-m-d H:i:s for the UTC time of a given post. If I am in the
>>> eastern timezone I am currently at -5 hours from UTC so when I make my
>>> post at 1:00pm eastern time, the time I see dispalyed on the page is
>>> 6:00pm because it is 6:00pm UTC. How can I take that UTC datetime
>>> stamp and convert it to the correct datetime given a specific php
>>> timezone such as America/New_York? I know there must be a simple way
>>> to do this I just haven't been searching the right words or
>>> something. Please help! Thank you!!!
>> Among other ways:
>>
>> echo strftime('%Y-%m-%d %H:%M:%S', strtotime('2008-12-02 20:50:00Z'));
>>
>> or
>>
>> echo date('Y-m-d H:i:s', strtotime('2008-12-02 20:50:00Z'));
>>
>> prints:
>>
>> 2008-12-02 15:50:00
>>
>> (U.S. Eastern Standard Time)
>>
>> (Note: the 'Z' at the end of the string is important - it means the
>> input is in Zulu (UTC) time).
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================
>
> Thank you Jerry:
> I think that would work if the user selects a timezone and I set that
> timezone on the website using date_default_timezone_set(). The
> problem is, when I need to write a date/time back to the database, I
> need to set the timezone back to UTC. Is there anything I can do to
> convert on the fly rather than constantly switching back and forth
> with the date_default_timezone_set() function?
php.net is your friend.
http://www.php.net/manual/en/function.gmstrftime.php
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
|