Jump to content

how reliable putenv ('TZ=MYTIMEZONE')


abdfahim

Recommended Posts

I've used this in a custom script I wrote for a deals website (similar to groupon), it seems to work pretty good.  I put it to my timezone (MST), I also tried PST, GMT, CST and other various ones around the world and it seemed to always be correct.

 

When doing a count-down it's easier to use this method than any other really.  When displaying a date, I imagine it'd be easier to use the +/- hours to display the time and if the user hasnt selected their timezone then it would default to the server time. which you would do similar to this:

$now = date('Y-m-d : H-M-S');

$date = date('Y-m-d', strtotime("$now +1 week"));

 

although since your datetime will probably come from an sql database with the type of DATETIME which was (should be) set using now(); you'd end up doing $now = $_query['post_date']; and then it should perhaps work.

 

Hi,

 

Thanks for your thought. Actually, I opted for using +/- for having my time, but my server time and PHP time output is behaving mysteriously. I live in UTC+6, and my server in UTC-5, so normally I added 11 hours and it was working fine. Suddenly, from this morning, PHP time is showing 1 hour back in server (hence UTC-6), though I have confirmed from hosting provider that they are still in UTC-5 (no DST).

 

I have opened a thread about that

 

http://www.phpfreaks.com/forums/php-coding-help/mismatch-between-server-time-and-php-time/

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.