Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about a Class and Date Time

Status
Not open for further replies.

timgerr

IS-IT--Management
Jan 22, 2004
364
US
Hello all, I have a question for ya, I have created a class to change time zones, using Pear's Date.php
Here is my class:
Code:
class DateClass{
        function GMT()
        {
                $nowGMT =  date('U') . "<br/>";
                $ets = strftime($nowGMT); // this is GMT
                $ESTFull = date('Y-m-d H:i:s',$ets);

                require_once 'Date.php';
                $now = new Date($ESTFull);
                // I have to set $now to the correct time zone
                // America/Detroit
                $now ->setTZByID("America/Detroit");
                $timezone = new Date_TimeZone('Etc/Greenwich');
                $now->convertTZ($timezone);
                return  $now->getDate();
        }

        function TZ($timeZone)
        {
                $nowGMT =  date('U') . "<br/>";
                $ets = strftime($nowGMT); // this is GMT
                $ESTFull = date('Y-m-d H:i:s',$ets);

                require_once 'Date.php';
                $now = new Date($ESTFull);
                // I have to set $now to the correct time zone
                // America/Detroit
                $now ->setTZByID("America/Detroit");
                $timezone = new Date_TimeZone($timeZone);
                $now->convertTZ($timezone);
                return  $now->getDate();
        }
}

so I create another page to try the methods
Code:
require('DateClass.php');
        $nd = new DateClass;
        echo '<br/>';
        echo $nd->GMT();
        echo '<br/>';
        echo $nd->TZ('Pacific/Fakaofo');
        echo '<br/>';
        echo $nd->TZ('America/Detroit');

and here is my output:
Code:
2008-09-11 14:47:36
2008-09-11 08:47:36
2008-09-11 04:47:36
OK, the first one is correct that is GMT time.
The 2nd one is correct for Pacific/Fakaofo.
The 3rd is incorrect, it should be -04 from the first one, GMT and the correct time should be
Code:
2008-09-11 10:47:36
I am not sure why the method is not returning to GMT to do the conversion. Any ideas?

Thanks,
Timgerr


-How important does a person have to be before they are considered assassinated instead of just murdered?
So there you go! You're the retarded offspring of five monkeys having butt sex with a fish-squirrel! Congratulations!


 
Have you tried displaying GMT again to see what happens? Start troubleshooting it - experiment with other expected results and you will soon find where it is breaking.

Steve
- I have fun with telemarketers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top