Converting timezone

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
jnikho
Forum Newbie
Posts: 1
Joined: Sun Oct 29, 2006 9:12 pm

Converting timezone

Post 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
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Is Date.php in the same folder as showTime.php?
User avatar
theYinYeti
Forum Newbie
Posts: 15
Joined: Thu Oct 26, 2006 3:33 pm
Location: France

Post 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.
Post Reply