The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Noob-ish timezone question - set_default, or convert?
Discuss Noob-ish timezone question - set_default, or convert? in the PHP Development forum on Dev Shed. Noob-ish timezone question - set_default, or convert? PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 26th, 2012, 03:20 PM
|
|
Contributing User
|
|
Join Date: Feb 2007
Posts: 50
  
Time spent in forums: 12 h 29 m 49 sec
Reputation Power: 9
|
|
|
Noob-ish timezone question - set_default, or convert?
Hi,
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
Code:
date_default_timezone_set($users_timezone_from_ajax)
, 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.
-unsub
Last edited by unsub : November 26th, 2012 at 04:23 PM.
|

November 26th, 2012, 05:18 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
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
|
|
Contributing User
|
|
Join Date: Feb 2007
Posts: 50
  
Time spent in forums: 12 h 29 m 49 sec
Reputation Power: 9
|
|
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
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
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
|
|
Contributing User
|
|
Join Date: Feb 2007
Posts: 50
  
Time spent in forums: 12 h 29 m 49 sec
Reputation Power: 9
|
|
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.
Best regards,
-unsub
|

November 26th, 2012, 11:54 PM
|
 |
Contributing User
|
|
Join Date: Sep 2002
Location: Seattle, U.S.A.
Posts: 712
 
Time spent in forums: 4 Days 11 h 4 m 59 sec
Reputation Power: 11
|
|
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|