Time zones: what dates will visitors see?

Discussion in 'PHP' started by croni, Jun 28, 2006.

  1. #1
    My webserver's located in Switzerland, so server time should be GMT+1h. Now what will a visitor see, when I echo something like date('Y-m-d h:i:s', time())? Will a visitor from say the U.S. see Switzerland's time, or will he see e.g. GMT-8h (I guess so...)?

    Thx!
     
    croni, Jun 28, 2006 IP
  2. Jean-Luc

    Jean-Luc Peon

    Messages:
    601
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Your php-program runs on the server in Switzerland and does not know anything about the location of your visitors. The time shown will be the Swiss time.

    Jean-Luc
     
    Jean-Luc, Jun 28, 2006 IP
  3. ServerUnion

    ServerUnion Peon

    Messages:
    3,611
    Likes Received:
    296
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You will have to adjust for timezones, or use clientside scripting to get the users local time to display. Good luck...
     
    ServerUnion, Jun 28, 2006 IP
  4. croni

    croni Peon

    Messages:
    66
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hmmm... how can I do this - preferably on the server side? Isn't there information about a client's timezone included in the Http-Request?
     
    croni, Jun 28, 2006 IP
  5. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Use geolocation to find the clients timezone from the IP and calculate the time difference from them to your web server.
     
    mad4, Jun 28, 2006 IP
  6. Jean-Luc

    Jean-Luc Peon

    Messages:
    601
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #6
    It is not easy to do it on the server and I don' t even see the benefit of doing it on the server, except if you need the visitor's local time for something else, of course.

    I would suggest you to google for JavaScript clock. There are plenty of short JavaScript examples available.

    Jean-Luc
     
    Jean-Luc, Jun 28, 2006 IP
  7. croni

    croni Peon

    Messages:
    66
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thing is, I have the date of an user event stored in my database. So I'd like to convert that date into the user's timezone. I guess Javascript is no option then, is it?
     
    croni, Jun 28, 2006 IP
  8. waffles

    waffles Peon

    Messages:
    87
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Just a thought, but if there's any need to keep the events in order wouldn't it make more sense to have everything running based on the same time zone?
     
    waffles, Jun 28, 2006 IP
  9. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #9
    You can use javascript to get the users time then an AJAX call to update the database if thats what you are looking for.
     
    mad4, Jun 28, 2006 IP
  10. croni

    croni Peon

    Messages:
    66
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Well, no. My tool is a kind of web analytics tool that logs search terms. So the user includes a line of javascript on his pages, and the tool logs the search terms used by his search engine visitors. Along with the search terms the server then writes the date&time when a term has been logged into the database. When displaying the latest search terms, the user will want to see the time of his timezone, not the one of the server I guess...
     
    croni, Jun 28, 2006 IP