Date not adjusting for timezones

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cone13cone
Forum Newbie
Posts: 24
Joined: Fri Mar 20, 2009 8:32 pm

Date not adjusting for timezones

Post by cone13cone »

I have this bit of code on one of my pages, it works although it echos back the time of the timezone that the server is on, whats the easiest way to adjust for my timezone with is three hours ahead of this time? WST -> EST

Code: Select all

 
<?php echo date('l jS \of F Y h:i:s A'); ?>
 
Thanks, John
Darkzaelus
Forum Commoner
Posts: 94
Joined: Tue Sep 09, 2008 7:02 am

Re: Date not adjusting for timezones

Post by Darkzaelus »

Code: Select all

<?php echo date('l jS \of F Y h:i:s A', time()+180); ?>
Darkzaelus
JasonDFR
Forum Commoner
Posts: 40
Joined: Wed Jan 07, 2009 3:51 am

Re: Date not adjusting for timezones

Post by JasonDFR »

I was going to say that calling date_default_timezone_set() in your script is the easiest way, but maybe not the best, but before I finished writing this, I decided that all of these options are pretty easy.

You can use: php_value date.timezone America/New_York in a .htaccess file.

Some hosts will parse php.ini files when they are inside the web root ( public_html or www ) usually. I'm not sure if this works for files contained in subdirectories.

If your site uses a common config file included in all pages, you can call date_default_timezone_set() in it.
JasonDFR
Forum Commoner
Posts: 40
Joined: Wed Jan 07, 2009 3:51 am

Re: Date not adjusting for timezones

Post by JasonDFR »

Darkzaelus wrote:

Code: Select all

<?php echo date('l jS \of F Y h:i:s A', time()+180); ?>
Darkzaelus
The above adds 3 minutes to the server time.
Post Reply