Thread: Users Timezone
View Single Post
Old 09-26-2007, 09:14 AM   #2 (permalink)
Wildhoney
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
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