How to display time local to a user?

by 3 replies
4
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
#programming #display #local #time #user
  • 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
    • [1] reply
    • 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
  • Banned
    [DELETED]
    • [1] reply
    • Before jumping into diving into how to format a date;

      do you already have the ability to geocode? ....

Next Topics on Trending Feed