NYCPHP Meetup

NYPHP.org

[nycphp-talk] Localizing Time Zones

Chris Shiflett shiflett at php.net
Tue Aug 12 16:05:33 EDT 2003


--- D C Krook <dkrook at hotmail.com> wrote:
> We've been looking for a good way to customize a web-based work
> flow tool so that each user who logs in sees the time stamp of
> events in his own time zone, not that of the server.

I take a slightly different approach than what you mention. I can't say that
I've ever given it a lot of thought, but this is what I do. I begin with some
default variables for the application:

$date_format = 'D, d M Y H:i:s';
$gmt_offset = -4;

If the user logs in, these values are overwritten with the user's session, so
you can let your users choose their preferred date format and time zone.

Then I just do something like this to get a ready-to-display date into a
variable:

$curr_date = gmdate($date_format, time() + $gmt_offset * 3600);

Of course, this demonstrates a date relative to the current time, but this can
be applied to any timestamp.

Hope that helps.

Chris

=====
Become a better Web developer with the HTTP Developer's Handbook
http://httphandbook.org/



More information about the talk mailing list