Jump to content

How to auto-adjust time by users' timezone ?


terryds

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 ?

Link to comment
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
Link to comment
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.

Link to comment
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.

Link to comment
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 :)

Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...