How to display time local to a user?

3 replies
Hello

At sign-up, I collect the user's country and set the nearest timezone (they can change this if it is incorrect).

I want to display time local to a user. How can this be done?


Thanks
#display #local #time #user
  • Profile picture of the author m4rx
    You could use somthing like below.
    $user_tz = 5; // Timezone
    $user_offset = $user_tz * 3600; // Number of hours X number of minutes X number of seconds
    $timestamp = time(); // Current Time
    $local_timestamp = $timestamp + $user_offset; // Current time in user's timezone.

    --m4rx
    Signature
    We are what we repeatedly do. Excellence, then, is not an act, but a HABIT. ~Aristotle
    Bored. Learn everything you need to know about Organic Gardening.
    {{ DiscussionBoard.errors[1736944].message }}
    • Profile picture of the author ariefsyu
      Originally Posted by m4rx View Post

      You could use somthing like below.
      $ user_tz = 5; // Timezone
      I think virtualmisc want to know how he can get the timezone. here's the way :

      PHP Code:
      <?php
      ip = $ _SERVER ['REMOTE_ADDR'];
      xml =  file_get_content("http://ipinfodb.com/ip_query.php?ip=". $ ip);
      //you may need to remove the spaces.
      ?>
      you'll have an xml file containing user's geo information, including the timezone. from there, you can use m4rx's code to view the user's local time

      hope this could help.
      Arief
      {{ DiscussionBoard.errors[1737874].message }}
  • Profile picture of the author weaverIT
    Banned
    [DELETED]
    {{ DiscussionBoard.errors[1740695].message }}
    • Profile picture of the author chaos69
      Before jumping into diving into how to format a date;

      do you already have the ability to geocode? ....
      Signature
      Best Ways To Make Money Online

      Eight bytes walk into a bar. The bartender asks, “Can I get you anything?”
      “Yeah,” reply the bytes. “Make us a double.”
      {{ DiscussionBoard.errors[1741306].message }}

Trending Topics