Page 1 of 1

Converting timezone

Posted: Mon Oct 30, 2006 12:18 pm
by jnikho
I was trying to figure out how to convert between timezones and several google sites are recommending to use the perl Date class because one does not have to worry about daylight saving time and others. To use the perl Date class, one must include ("Date.php") in the php file. But when executing the php file that contains the include ("Date.php"), I am getting the following error message:

Warning: main(Date.php) [function.main]: failed to open stream: No such file or directory in /myhome/public_html/showTime.php on line 2

Warning: main() [function.include]: Failed opening 'Date.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /myhome/public_html/showTime.php on line 2

Posted: Mon Oct 30, 2006 3:35 pm
by aaronhall
Is Date.php in the same folder as showTime.php?

Posted: Mon Oct 30, 2006 5:00 pm
by theYinYeti
I did a lot of research on the topic of timezones for my home-made framework, some time ago.
I had come to the conclusion that PHP is just unable to deal with timezones. You have to do it all by yourself.

Your dates should be stored internally using a reference zone (eg: GMT), and you have to compute locale date/times using PHP code.

If I remember correctly, the easiest way is to set the TZ variable from PHP and then ask for the date corresponding to your GMT date (or the reverse). Unfortunately, this won't work if the server runs Windows.

So I went for the second route, because I wanted my framework to work on both Windows and Linux. This second method is to do all the computing. TZ is handy because it "contains" all the time shifts specifications, the special dates and hours... Without TZ, you have to know, for the local time you want to deal with: the usual shift from GMT, the date at which summer time begins and ends if necessary, and the new shift from GMT (in summer).
Then is is only comparisons, additions, and substractions.

Yves.