Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #14424

Re: Dealing with timestamps from different timezones - general approach for basic saving?

From Jerry Stuckle <jstucklex@attglobal.net>
Newsgroups comp.lang.php
Subject Re: Dealing with timestamps from different timezones - general approach for basic saving?
Date 2014-10-28 16:51 -0400
Organization A noiseless patient Spider
Message-ID <m2ovkq$1c3$1@dont-email.me> (permalink)
References <cd058cd0-6ace-447c-b4cf-482117630dc0@googlegroups.com>

Show all headers | View raw


On 10/28/2014 3:42 PM, e.blumstengel@googlemail.com wrote:
> Hey there,
> 
> I have a short question about internationalized systems and the saving of timestamps. 
> 
> Scenario:
> Users from different countries post blod entries into a php-based system. The blog entries will have a created and a modified timestamp (actually a datetime-field in a MySQL-db).
> 
> What is the best approach to save the timestamp, so that the information when the "real" creation date will still preserved?
> 
> When a user from let's say Brazil views an entry from a user that posted from Hong Kong, he/she should see the date(time) in his/her "timezoned" timestamp.
> 
> My approach would be to save all dates/datetimes in UTC as a general information, and then apply the timezone-offset depending on the current viewer (e.g. the user that requests the blog entry). Otherwise I'd need to save the timezone(offset) for every entry in the DB, which could be useful, or overhead....
> 
> 
> What are your approaches for real-life scenarios when dealing with users from different timezones? Any help is much appreciated...
> 

The problem here is knowing what the user's timezone is.  You can tell
when the blog was posted, of course, and really don't care about the
user's timezone.  You can save it in any timezone you wish, but
typically it's either UTC or the timezone of your server.

But when retrieving the blog entry, you don't know the reader's timezone
(unless they've logged in and set it in their profile).  Your only real
choices here are to:

1. Ask for their timezone and save it in a cookie (an extra operation on
their part)
2. Use javascript to fetch the user's timezone and display it
accordingly (off topic in a PHP newsgroup)
3. Use a combination of #1 and #2 and set a cookie with the timezone,
but it won't work on the first page they display (because the javascript
doesn't run until after the page is displayed.  You would have to use
javascript to reload the page.
4. Display the time in a standard format (i.e. UTC) or, if your readers
are pretty much all U.S. based, something like EST/EDT or PST/PDT.

Each has its advantages and disadvantages; it's up to you to determine
which you wish to use.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Dealing with timestamps from different timezones - general approach for basic saving? e.blumstengel@googlemail.com - 2014-10-28 12:42 -0700
  Re: Dealing with timestamps from different timezones - general approach for basic saving? Jerry Stuckle <jstucklex@attglobal.net> - 2014-10-28 16:51 -0400
    Re: Dealing with timestamps from different timezones - general approach for basic saving? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-10-30 08:14 +0100
      Re: Dealing with timestamps from different timezones - general approach for basic saving? Jerry Stuckle <jstucklex@attglobal.net> - 2014-10-30 10:04 -0400
        Re: Dealing with timestamps from different timezones - general approach for basic saving? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-10-30 22:38 +0100
          Re: Dealing with timestamps from different timezones - general approach for basic saving? Jerry Stuckle <jstucklex@attglobal.net> - 2014-10-30 18:38 -0400
            Re: Dealing with timestamps from different timezones - general approach for basic saving? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-10-31 05:33 +0100
              Re: Dealing with timestamps from different timezones - general approach for basic saving? Jerry Stuckle <jstucklex@attglobal.net> - 2014-10-31 09:51 -0400
                Re: Dealing with timestamps from different timezones - general approach for basic saving? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-01 09:31 +0100
                Re: Dealing with timestamps from different timezones - general approach for basic saving? Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-01 09:31 -0400
                drifted into ABUSE: Re: Dealing with timestamps bill <william@TechServSys.com> - 2014-11-01 11:21 -0400
                Re: drifted into ABUSE: Re: Dealing with timestamps Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-01 17:04 +0100
                Re: drifted into ABUSE: Re: Dealing with timestamps Jerry Stuckle <jstucklex@attglobal.net> - 2014-11-01 21:32 -0400
                Re: drifted into ABUSE: Re: Dealing with timestamps Tim Streater <timstreater@greenbee.net> - 2014-11-02 09:27 +0000
  Re: Dealing with timestamps from different timezones - general approach for basic saving? Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-29 01:50 +0000

csiph-web