Reputation: 396
I have a presenter and viewer on site collaborating globally They are both registered users with their location (city/state/country) stored in mysql
meeting times are displayed to both users on php based on one of the users local time, i would like other user's time adjusted accordingly based on first user's location. (keeping in mind daylight saving in USA)
or alternatively
i would like all USA timezone self updating clocks displayed on the webpage
how can this be done?
Upvotes: 0
Views: 819
Reputation: 1745
In the database, I would store the original meeting time in UTC. I would also have a field on the user table to assign a TZ category.
A simple if/then for daylight savings is active on that date, and then convert the time.
I'd use php for all of it. Since you can combine the db pull to include UTC + TZ alteration in the same query. Then, adjust for daylight savings if necessary.
Upvotes: 1
Reputation: 1625
This could be done via javascript and (cookie witch could save the client timezone, or ajax to send it back to the server). Then you could use it on PHP script to make the adjustments. In javascript use getTimezoneOffset() method. Here is a simple script for using it:
<script type="text/javascript">
var d = new Date()
var gmtHours = -d.getTimezoneOffset()/60;
document.write("The local time zone is: GMT " + gmtHours);
</script>
Upvotes: 0
Reputation: 1209
Store all times globally in UTC. When displaying time, first find out what timezone the user is (client side or server side) and change the time accordingly through php or javascript. When setting time, ensure that you also take the users timezone out of the equation and store it as UTC again.
Upvotes: 0