TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-26-2007, 01:22 AM   #1 (permalink)
The Acquainted
Upcoming Programmer 
 
CMellor's Avatar
 
Join Date: Sep 2007
Location: Leeds, UK
Posts: 141
Thanks: 6
CMellor is on a distinguished road
Default Users Timezone

Hey, hope all are well. I have a question.

My project is pretty big, and can only hope for global success. Currently all the times on the website are using the server's clock, which is 6 hours behind my clock (It's in the USA and I'm in the UK). I will allow my users to set there timezone via a select menu, the same as a lot of forums (including this one) use in it's control panel. I'll be storing the value in the 'member' table.

What I'm not 100% sure on is how to use the value to display the time in their timezone. My timezone would be '0 - GMT' but with the server time been six hours behind my clock, would I add '+6' instead? When I output a time, I want it to be the time in their timezone, so, my first though was to do something like this:

Code:
echo date('D M, Y' time()+$row->timezone);
If anyone has any discussions on this, I look forward to hearing them :)

P.S. Hope I made sense :P
__________________
Not quite a n00b...
CMellor is offline  
Reply With Quote
Old 09-26-2007, 10:14 AM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,258
Thanks: 90
Wildhoney is on a distinguished road
Default

I'd go one of two, maybe three ways at a push, in achieving this.

Method 1: Using strtotime()
Downsides: Not the fastest function in the world but gets the job done.

PHP Code:
echo date('H:i:s D M, Y'strtotime('+6 hours')); 
Method 2: Using mktime()
Downsides: Long line. Uses functions inside functions which can look exceptionally messy.

PHP Code:
echo date('H:i:s D M, Y'mktime(date('H') + 6date('m'), date('Y'), date('m'), date('d'), date('y'))); 
Method 3: The proper way! Using date_default_timezone_set or putenv
Downsides: Very little! Just wish this function was more heard of.

PHP Code:
putenv('TZ=US/Eastern'); // Using putenv. Good for pre PHP5.
echo date('H:i:s D M, Y'); 
PHP Code:
date_default_timezone_set('US/Eastern'); // How to do it now we have PHP5
echo date('H:i:s D M, Y'); 
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 09-26-2007, 11:12 PM   #3 (permalink)
The Acquainted
Upcoming Programmer 
 
CMellor's Avatar
 
Join Date: Sep 2007
Location: Leeds, UK
Posts: 141
Thanks: 6
CMellor is on a distinguished road
Default

While date_default_timezone_set looks tempting, I can't see how it would work with the values of the select menu, which will be '0, +1, +2... -2, -1' etc. Unless those values would work with the $timezone_identifier, but I see no mention of that in the manual. I think I may just go with strtotime()

Unless anyone has any follow up's to my query, thanks for the help Wild Honey.
__________________
Not quite a n00b...
CMellor is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 10:43 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design