in reply to How to get client-side's localtime from the server-side

Cannot be accomplished.
  • Comment on Re: How to get client-side's localtime from the server-side

Replies are listed 'Best First'.
Re^2: How to get client-side's localtime from the server-side
by b4swine (Pilgrim) on Aug 06, 2007 at 00:56 UTC
    How about getting client IP (which can be done), converting that to approximate geographical location, and from there to some approximation of time zone. At least one can figure out whether to say "good evening" or "good morning", based on this crude idea.

      You could do that, but it's important to understand that it's a heuristic and not a real concrete method.

      Another heuristic might be to look at the language preference information you get from the browser. You can guess that "en-US" is probably one of four time zones.

      Still another would be a wild guess based on the server's local time. You can guess that most of your hits at any time of day come from time zones that are in "waking hours" at that time (i.e., the Australians are active at a different time than the Americans).

      Quite a few sites I've been to (including this one) ask me my time zone as part of my user preferences. This is evidence enough for me that there isn't a good and easy solution to this problem.

        it's important to understand that it's a heuristic and not a real concrete method.
        I would never call it a heuristic since it makes use of a database lookup. The database can be huge. By contrast, a heuristic makes a guess based on (very) limited info.

        If you use Geo::IP you can use the free though somewhat limited database, or, if you want a better precision — and likely, fewer errors, then you can pay for a bigger, commercial database from the same company who brought you the module.

        n.b. I see that for the latter they require you need to be an "established business". That may be out of the reach of many developers here who may be wanting to use it for their own little projects.

        Personally I think I'd go for the Lite version, and give the user the option to correct the guessed time zone, possibly making use of Javascript to automate it, for people who have Javascript enabled for your site.