15 Replies Latest reply on Feb 16, 2011 12:56 PM by kglad

    timeIssue

    Ron Colmen Level 2

      For some reason I'm unable to output the time returned by the php. This code is on my website and viewrs from different countries see different times.

       

      <?php

      date_default_timezone_set('Europe/Lisbon');

      echo time();

      //output example 1297797784

      ?>

       

       

      AS

       

      var tl:MovieClip=this;

      var startTime:Number;

       

      server = new LoadVars();

      server.onData = function (src){

      tl.timeMS = Number(src);

      startTime=getTimer();

      clock_txt.onEnterFrame = timeF;

      };

      server.load("http://www.myweb.com/timeServer.php");

       

      function timeF(){

      //var d:Date = new Date(tl.timeMS*1000+getTimer()-startTime);

      var d:Date = new Date(tl.timeMS*1000);

      //when I tried this, it displayed my local time.

      if(d.getHours()>12){

      var hours:Number=d.getHours()-12;

      var ampm:String = "PM";

      } else if(d.getHours()==12){

      hours=12;

      ampm="PM"

      } else {

      hours=d.getHours();

      ampm="AM";

      }

      var hoursS:String = formatS(hours.toString());

      var minutes:String = formatS(d.getMinutes().toString());

      var seconds:String = formatS(d.getSeconds().toString());

      _root.clock_txt.clock_txt.text = hoursS + ":" + minutes + ":" + seconds +" "+ ampm;

      }

       

      function formatS(s:String):String{

      while(s.length<2){

      s="0"+s;

      }

      return s;

      }

        • 1. Re: timeIssue
          kglad Adobe Community Professional & MVP

          :

           


          <?php

          date_default_timezone_set('Europe/Lisbon');

           

          echo time();

          //output example 1297797784

          ?>

           

           

          AS

           

          var tl:MovieClip=this;

          var startTime:Number;

           

          var sendLV:LoadVars = new LoadVars();

          var receiveLV:LoadVars=new LoadVars();

          receiveLV.onData = function (src){

          tl.timeMS = Number(src);

          startTime=getTimer();

          clock_txt.onEnterFrame = timeF;

          };

          sendLV.sendAndLoad("http://www.myweb.com/timeServer.php",receiveLV,"POST");

           

          function timeF(){

          //var d:Date = new Date(tl.timeMS*1000+getTimer()-startTime);

          var d:Date = new Date(tl.timeMS*1000);

          //when I tried this, it displayed my local time.

          if(d.getHours()>12){

          var hours:Number=d.getHours()-12;

          var ampm:String = "PM";

          } else if(d.getHours()==12){

          hours=12;

          ampm="PM"

          } else {

          hours=d.getHours();

          ampm="AM";

          }

          var hoursS:String = formatS(hours.toString());

          var minutes:String = formatS(d.getMinutes().toString());

          var seconds:String = formatS(d.getSeconds().toString());

          _root.clock_txt.clock_txt.text = hoursS + ":" + minutes + ":" + seconds +" "+ ampm;

          }

           

          function formatS(s:String):String{

          while(s.length<2){

          s="0"+s;

          }

          return s;

          }

          • 2. Re: timeIssue
            Ron Colmen Level 2

            No luck. It still shows the local time.

            • 3. Re: timeIssue
              kglad Adobe Community Professional & MVP

              what php version is on your server?   eg, using your browser, open the php file containing:

               

              <?php
              phpinfo();
              ?>

              • 4. Re: timeIssue
                Ron Colmen Level 2

                It's 5.2

                 

                 

                var d:Date = new Date(tl.timeMS*1000);

                trace (d);

                 

                 

                output:

                Wed Feb 16 14:47:07 GMT+1000 2011

                • 5. Re: timeIssue
                  kglad Adobe Community Professional & MVP

                  what's wrong with that date/time?

                  • 6. Re: timeIssue
                    Ron Colmen Level 2

                    That's the local time. tl.timeMS*1000 is supposed to be the time returned by the php.

                    • 7. Re: timeIssue
                      kglad Adobe Community Professional & MVP

                      that looks like the correct time in lisbon to me:  ~8 hours in advance of the pacific time zone.

                      1 person found this helpful
                      • 8. Re: timeIssue
                        Ron Colmen Level 2

                         

                        Even if I change the php to output any other timezone, I don't see a time change in my swf... it just outputs the local time.

                        date_default_timezone_set('Australia/Sydney');

                         

                         

                        is this bold text causing the problem?

                         

                         

                        tl.timeMS = Number(src);

                        startTime=getTimer();

                        clock_txt.onEnterFrame = timeF;

                         

                         

                        //rest of the code

                         

                        var hoursS:String = formatS(hours.toString());

                        var minutes:String = formatS(d.getMinutes().toString());

                        var seconds:String = formatS(d.getSeconds().toString());

                        _root.clock_txt.clock_txt.text = hoursS + ":" + minutes + ":" + seconds +" "+ ampm;

                        }

                         

                         

                        I tried altering... but nothing was displayed.

                         

                         

                        tl.timeMS = Number(src);

                        startTime=getTimer();

                        _root.clock_txt.clock_txt.onEnterFrame = timeF;

                         

                         

                        //rest of the code

                         

                        var hoursS:String = formatS(hours.toString());

                        var minutes:String = formatS(d.getMinutes().toString());

                        var seconds:String = formatS(d.getSeconds().toString());

                        _root.clock_txt.clock_txt.text = hoursS + ":" + minutes + ":" + seconds +" "+ ampm;

                        }

                         

                         

                         

                        • 9. Re: timeIssue
                          kglad Adobe Community Professional & MVP

                          why do you keep showing that screwy absolute url to your php file?

                          • 10. Re: timeIssue
                            Ron Colmen Level 2

                            I'm not sure if I red you correctly. Do you mean this? http://www.myweb.com/timeServer.php

                             

                            That's just for illustrative purpose.

                            • 11. Re: timeIssue
                              kglad Adobe Community Professional & MVP

                              yes, that's what i mean.  why don't you show your real url?  you are using a local path, correct?

                              • 12. Re: timeIssue
                                Ron Colmen Level 2

                                no. I've saved it in the ftp. I'm using a http://www. URL.to pull the time.

                                • 13. Re: timeIssue
                                  kglad Adobe Community Professional & MVP

                                  you should be using a local path though i don't know that will correct the problem.  in any case, the problem is on the server end.

                                  1 person found this helpful
                                  • 14. Re: timeIssue
                                    Ron Colmen Level 2

                                    Thanks. That's a good point.

                                     

                                    Any suggestions to fix this if the problem is on the server end?

                                    • 15. Re: timeIssue
                                      kglad Adobe Community Professional & MVP

                                      you can offset the old fashion way (use google), though php 5.1 or greater is supposed to support that date_default_timezone_set.