abdfahim Posted November 7, 2010 Share Posted November 7, 2010 As mentioned in subject, how reliable the following function is if I want to display time according to local timezone? putenv ('TZ=MYTIMEZONE'); Where MYTIMEZONE is from http://www.php.net/manual/en/timezones.asia.php Link to comment https://forums.phpfreaks.com/topic/217992-how-reliable-putenv-tzmytimezone/ Share on other sites More sharing options...
radar Posted November 7, 2010 Share Posted November 7, 2010 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. Link to comment https://forums.phpfreaks.com/topic/217992-how-reliable-putenv-tzmytimezone/#findComment-1131329 Share on other sites More sharing options...
abdfahim Posted November 7, 2010 Author Share Posted November 7, 2010 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/ Link to comment https://forums.phpfreaks.com/topic/217992-how-reliable-putenv-tzmytimezone/#findComment-1131331 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.