Best way to get clients local time.

oracle

New Member
Messages
430
Reaction score
0
Points
0
Hi I have a kindda forum and chat room, where users can poll thr messages etc etc.

However I don't know what is the best way to manage time. I mean suppose we have 2 users, one in US and one in India.

Now both messages in the chat room and there messages gets saved in the database tables. Now I want to have that when Indian user sees messsage of US user, he shd see at what time (India time) did he posted that message

Similarly vice-versa.

I have seen in a few forums on net, but I couldn'y find a concreate answer to this. Can someone thrown some light and probably help me in this ??
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
Most forums ask you to tell them what your timezone is (remember joining x10?)
Making sure the users see the right time isn't a problem, just store the time in your database, together with the posts etc. And when the user views the page, you should determine what the time difference between the stored time is and the user time. (for example, if you store your time for GMT, and the user lives in +6, you have to add 6*60*60 seconds to the stored time to get the user's time)
 

oracle

New Member
Messages
430
Reaction score
0
Points
0
Ya but what in case of sites like orkut, facebook. They never took our time zone entries but still r able to show the correct times.

Do they link directly with country ??
 

gamerdude

New Member
Messages
101
Reaction score
0
Points
0
Probably a quick whois lookup. But that isn't always right. Or they asked you where you live.
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
They could use javascript to get the clients time and pass it to the server, perhaps something like this:
when the page loads, there's 2 possibilities:
- there's a cookie with the user's timezone offset
- there's no cookie

if there's a cookie: use it to calculate the right time
if there's no cookie: send a page with some javascript on it, the javascript executes and redirects the user to another page, that page receives the user's time (thanks to the javascript) and calculates the timezone offset, which can be stored in a cookie

it's just an idea, but it shows there's always a possibilitie
 

oracle

New Member
Messages
430
Reaction score
0
Points
0
Ya thats what I am doing exactly, I am taking users local time through ajax and doing the processings but I am still in doubt over whether this is the correct method.

I dont think orkut and facebook use this methodology for this.

And what if user doesnt have javascript enabled ??
 

gamerdude

New Member
Messages
101
Reaction score
0
Points
0
Then you ask them for their timezone. Since server-side scripts can't get the clients time, you have to rely on client-side scripting, like javascript.
 
Top