ERuiz Posted January 15, 2007 Share Posted January 15, 2007 Say a member of my website lives in a timezone of -5 GMT, how would I be able to write a code so that when a person looks at this members information, it will show the current time for that member that lives in -5 GMT?Thanks,ERuiz Link to comment https://forums.phpfreaks.com/topic/34206-determine-a-users-local-time/ Share on other sites More sharing options...
btherl Posted January 15, 2007 Share Posted January 15, 2007 The easiest way is to ask the user at registration time.Of course many users will not know what time zone they are in, but they will know what country and area they are in, so it can be better to ask for that than for the time zone.If you want to automatically detect their time zone, look at "geolocation". That's the word for finding a user's physical location based on their ip address. Link to comment https://forums.phpfreaks.com/topic/34206-determine-a-users-local-time/#findComment-160946 Share on other sites More sharing options...
ERuiz Posted January 15, 2007 Author Share Posted January 15, 2007 Hi btherl,Actually, the timezone is already stored for each member on the database. So I just need to use the value stored and make the calculations from there.Example: $timezone = "-5";How would I write a php code to take $timezone and calculate local time using server's actual time? Link to comment https://forums.phpfreaks.com/topic/34206-determine-a-users-local-time/#findComment-160952 Share on other sites More sharing options...
btherl Posted January 15, 2007 Share Posted January 15, 2007 This function should help.. you can use it along with date() to format the timestamp nicely.http://sg.php.net/manual/en/function.mktime.phpAdd the timezone to the hours argument to adjust the time. Link to comment https://forums.phpfreaks.com/topic/34206-determine-a-users-local-time/#findComment-160957 Share on other sites More sharing options...
ERuiz Posted January 15, 2007 Author Share Posted January 15, 2007 Thanks!!! ;) Link to comment https://forums.phpfreaks.com/topic/34206-determine-a-users-local-time/#findComment-160959 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.