how to make all users on site share a universal timezone using php or javascript?
I'm using this great jQuery timepicker http://trentrichardson.com/examples/timepicker/
It gives a string something like 07/20/2011 01:13 am
I have this situation where users on the site can schedule "events" and they are using this to pick the event. But im realizing that it could cause a lot of confusion with all the different timezones that people will be submitting from.
So I was thinking I could use php to somehow get the timezone, and the adjust how the viewer views the dates according to their timezone. But this seems like quite a task and was wondering if there was an easier way?
Also, even with the php idea I tried echo dat开发者_StackOverflowe_default_timezone_get();
as a test to see if it got my timezone, but its saying im in the Los Angelas timezone, rather than Baltimore/DC timezone.
I'm guessing its getting the timezone of my server since php is serverside.
So basically, whats the best way while using my time picker jquery script, that I can have all the users view the date/times adjusted to their timezones? Any help would be greatly appreciated.
when you get the datetime from user, save in a default timezone (GMT 0 for example), you need to know the user timezone. When you get the datetime from DB, add the user timezone to it.
You are right, the default timezone is the server's.
get user timezone you can save it in cookie
The term is UTC Time, Universal Coordinated Time. Googling that will find you a lot, in the meantime:
http://www.w3schools.com/jsref/jsref_getutcdate.asp
Direct give the UTC time (e.g. "Wed, 20 Jul 2011 06:10:38 GMT") to the users and use JS to convert it to their local times.
var localTime = new Date("Wed, 20 Jul 2011 06:10:38 GMT");
alert(localTime); // shows local time like: "Wed Jul 20 2011 14:10:38 GMT+0800 (CST)"
精彩评论