Jump to content
Sign in to follow this  
terryds

How to auto-adjust time by users' timezone ?

Recommended Posts

How to auto-adjust the time by users' timezone ?

Must the user fill the form asking for his/her timezone ?

Do browsers send the user timezone information when interacting with the server ?

Can we just use PHP to auto-adjust the time ? Or, Do we need javascript ?

Share this post


Link to post
Share on other sites

Most systems give the user a dropdown with a list of time zones to choose from. The settings for the user are saved in a database. When the user is logged in, the user's settings are loaded from the database. Dates on the pages are shown in the user's timezone using methods such as DateTime::setTimeZone()

  • Like 1

Share this post


Link to post
Share on other sites

Fox,

 

What would be the best route to take if you try to adjust the time to the users local time without asking them for their timezone etc? I understand using the browser via Javascript is not a good idea because their clock on the computer can be wrong but getting their timezone at least via Javascript can be an option to take because from there you can calculate what the correct time is for them using the timezone supplied from Javascript and the server time?

 

Apologies if this is hijacking the thread. If so, this post can be deleted.

Share this post


Link to post
Share on other sites

That's not something most websites do. If you log out of the forum now you'll see that the post times are shown in UTC time.

 

If you want to figure out a user's time offset you can try Geolocation or have Javascript send their local time so you can compare it to the server's time. You can check the offset in hours between the the client and the server and add that to the dates before showing them. Some time zones have half-hour offsets, so you would probably have to take that into account as well.

Share this post


Link to post
Share on other sites

Most systems give the user a dropdown with a list of time zones to choose from. The settings for the user are saved in a database. When the user is logged in, the user's settings are loaded from the database. Dates on the pages are shown in the user's timezone using methods such as DateTime::setTimeZone()

 

That's not something most websites do. If you log out of the forum now you'll see that the post times are shown in UTC time.

 

If you want to figure out a user's time offset you can try Geolocation or have Javascript send their local time so you can compare it to the server's time. You can check the offset in hours between the the client and the server and add that to the dates before showing them. Some time zones have half-hour offsets, so you would probably have to take that into account as well.

 

Thanks for your answer :)

Share this post


Link to post
Share on other sites

That's not something most websites do. If you log out of the forum now you'll see that the post times are shown in UTC time.

 

 

I see, but many sites like Facebook for example adjust the time for their users to the users' local time without asking them for their timezone etc.

Share this post


Link to post
Share on other sites

They ask the users for their location, I presume. I'm not on Facebook so I don't know. They can figure out the timezone from the geographical location. That would require a large database of locations and associated time zones.

Share this post


Link to post
Share on other sites

 

 

I see, but many sites like Facebook for example adjust the time for their users to the users' local time without asking them for their timezone etc.

 

Hmm.. maybe, Facebook uses IP Address to track the location.

 

$_SERVER['REMOTE_ADDR']

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...