Problem in setting timezone

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Muddasir
    New Member
    • Jun 2007
    • 49

    Problem in setting timezone

    Hi everyone

    I want to set timezone (US/Central). It is working fine on my local computer but when I upload the code on web server It is giving me error

    Fatal error: Call to undefined function: timezone_open() in

    Here is the code

    Code:
    $tz1 = timezone_open("US/Central"); 
    $ts = date_create("2008-08-19 12:19:21", $tz1);  
    echo $ts->format(DATE_RFC822), "<br/>";$ts->setTimezone($tz1);
    If anyone could help me

    Regards
    Last edited by Dormilich; Sep 23 '10, 06:30 PM.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    what php version does the server use? timezone_open() requires PHP 5.1.0 at least.

    Comment

    • biliards
      New Member
      • Sep 2010
      • 3

      #3
      Hi all,

      I have the same error log:
      Code:
      Fatal error: Call to undefined function: timezone_open() in
      with simple script:
      Code:
      <?php
      $t=time();
      echo($t . "<br />");
      $date = timezone_open($t);
      echo $date;
      ?>
      and PHP 5.2.14 (cli) (built: Aug 27 2010 16:40:16)

      Can someone give me a tip?

      Best,

      Biliards.

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Are you 100% sure about that version number? (A 110% sure?) - I've lost count how many hours I've wasted because I assumed things like that without properly testing for it :)

        That said, did you try bypassing the alias function and just using the normal OOP method?
        [code=php]<?php
        $d = new DateTimeZone(ti me());
        echo $d;
        ?>[/code]

        Comment

        • biliards
          New Member
          • Sep 2010
          • 3

          #5
          Hi Atli,

          yes, I'm sure:
          Code:
          # php -v
          PHP 5.2.14 (cli) (built: Aug 27 2010 16:40:16) 
          Copyright (c) 1997-2010 The PHP Group
          Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
              with the ionCube PHP Loader v3.1.29, Copyright (c) 2002-2007, by ionCube Ltd.
          I try your script and I obtain this error log
          Code:
          PHP Fatal error:  Class 'DateTimeZone' not found
          I don't understand why

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            That's really odd. According to the manual entry for that class it is supposed to be built into the PHP core since 5.2.0. Could it be that there is something special about your build? How did you install it?

            Also, looking at this more closely, you are not using the class as it should be used. The constructor takes a timezone name, not a timestamp. That is, you should pass it a string like: "GMT", "UTC", or even something like: "Iceland" or "America/New_York".

            Comment

            • Markus
              Recognized Expert Expert
              • Jun 2007
              • 6092

              #7
              Are you using the CLI PHP binary to test this, or are you testing through your webserver? Many times have we seen people give us the version of their CLI PHP binary, assuming it to be the same as the binary used by their webserver (it is typically not).

              Comment

              • biliards
                New Member
                • Sep 2010
                • 3

                #8
                Summary

                I'm sorry if I used the class as it should be used.
                Now, before to reply to thred, I used other Centos5 server with PHP4 and I used these command-line:
                Code:
                # yum update
                # php -v
                PHP 5.1.6 (cli) (built: Mar 31 2010 02:44:37) 
                Copyright (c) 1997-2006 The PHP Group
                Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
                # more test.php
                <?php
                $date = timezone_open('UTC');
                echo $date;
                ?>
                # php test.php
                PHP Fatal error:  Call to undefined function timezone_open() in ... on line 2
                So that I used two guides:
                * wiki.centos.org to update PHP from 5.1.6 to 5.2.10 but I had again the error log
                * jasonlitka.com to update PHP from 5.2.10 to 5.2.14 but I had again the error log

                Update from 5.1.6 to 5.2.10 was completed only after I erased php-sqlite2 (yum erase php-sqlite2).

                Comment

                Working...