November 26th, 2012, 03:20 PM
Noob-ish timezone question - set_default, or convert?
I have a situation where users' timezones need to be taken into consideration.
I have done it using some Ajax, the PHP side of which sets the default timezone to the user's timezone using
, in order to display a schedule retrieved from a list of times in a MySQL database.
It works, and probably better than it needs to, as total accuracy is not critical.
My question is:
Should I be using date_default_timezone_set like this? Or should I be finding a way display a converted version of the timestamp, while leaving the default timezone in tact @ UTC?
I think that mainly my problem is that I don't know if the default timezone is being changed ONLY for the current user...
Thanks for any advice you can give.
Last edited by unsub; November 26th, 2012 at 04:23 PM.
November 26th, 2012, 05:18 PM
What you're doing makes the most sense to me. The script is basically running in the "context" of the user: getting stuff from here, doing stuff over there, and formatting times. The user is in some timezone and so whatever the script shows should be in that timezone too. In fact it's quite unlikely that it'll have to do anything for a different timezone.
November 26th, 2012, 07:54 PM
OK, that's a word I should have been looking for "context"!
So my assumption is (and this is probably going to sound really silly to at least a few people...) that setting the default timezone is not doing anything that's going to effect other users. By "default" it only means the default timezone in the 'context' of that instance of the script?
The ability to set it in php.ini got me worrying... probably for no reason... I'm such a noob, jeez! :P
Thanks so much for your reply
November 26th, 2012, 08:46 PM
Exactly. Each running PHP script is completely independent from all the other running PHP scripts, be they the same file or not. Separate memory, separate variables, separate everything. You have to go out of your way to make them share information.
date_default_timezone_set() only sets the default timezone for the current script. Not like for the entire machine or for PHP as a whole.
November 26th, 2012, 10:43 PM
Well that helps a lot, both in the 'context' of this question, and in general. Thanks again!
Not sure if I need to mark this as [solved] or not... doesn't look to be the Devshed way, but I'll go and reread the forum guidelines.
November 26th, 2012, 11:54 PM