Re: [PHP] Using DateTimeZone



Lester Caine wrote:
I'm looking to tidy up things a bit by clearing out a lot of old code and switching to using the internal DateTime functions.

Information is stored in the databases UTC normalized, and we get around the problem of getting a real tz offset by getting the users to register it rather than simply relying on the browser. So dates and times are displayed either UTC or user local time. The server defaults are not relevant, as only the user details should be used.

OK cracked the first bit - need an '@' in place of the "U"

The thing that I am having a little trouble establishing is the correct way to take a UTC unix epoch timestamp from the data and display it with the users timezone offset.

$dateTimeZoneUser = new DateTimeZone("user's setting");
$dateTimeUser =
new DateTime( date( "U", $datetime_to_display ), $dateTimeZoneUser );
new DateTime( '@'.$datetime_to_display, $dateTimeZoneUser );
$date = $dateTimeUser->format( DATE_ATOM );

Is giving results wildly different from 2008
So how is one supposed to handle epoch values?
That gives me the correct date - but changing the timezone makes no difference to the output - seems to be displaying local timezone only.

I little aside while sorting the lookup table for timezones, DateTimeZone::listIdentifiers() apparently should accept a country code, but again I can't seem to find out how to make it work. Would I expect it to return just values for the country requested?

--
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/lsces/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php
.



Relevant Pages

  • Re: Remove Daylight Savings Time Dialog box?
    ... What what I've seen & read, XP is running UTC, and the timezone & daylight ... The problem I have with "scheduled a task that changed the timezone when DST ... > My first thought was that you could turn off the automatic adjustment for ... you would still get the correct time display. ...
    (microsoft.public.windowsxp.customize)
  • Re: [PHP] Using DateTimeZone
    ... Information is stored in the databases UTC normalized, and we get around the problem of getting a real tz offset by getting the users to register it rather than simply relying on the browser. ... correct way to take a UTC unix epoch timestamp from the data and display it with the users timezone offset. ... How do I get this translated to the users language as well as their timezone? ... Lester Caine - G8HFL ...
    (php.general)
  • Re: Requiring a date be entered as mm/dd/yy on a form field.
    ... specify that they cannot calculate to that precision. ... Furthermore, UTC ... use whatever standard they are given. ... Most areas have some name that they use to refer to their timezone. ...
    (microsoft.public.scripting.jscript)
  • Re: hwclock problem with leapseconds - posix?
    ... preferably i also want the rtc updated during normal running system, ... You are using modified TAI, ... I have no idea what a leapsecond respecting timezone is. ... served better by using UTC. ...
    (comp.os.linux.setup)
  • Re: hwclock problem with leapseconds - posix?
    ... a quick look shows that hwclock uses the routines mktime with the timezone ... I suspect that the assumption that we are using UTC, not TAI, and that the ... preferably i also want the rtc updated during normal running system, ...
    (comp.os.linux.setup)