A Flash Developer Resource Site

Results 1 to 20 of 27

Thread: Date and Time

Threaded View

  1. #19
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    The previous php file I posted returned the GMT time. If you want it to return local time, use this PHP file named servertime.php instead
    Code:
    <? echo time() + date("Z") ; ?>
    You can check if it works by viewing the file you uploaded to the server in your webbrowser. It should display a numeric value.

    Modified ActionScript code to use the server time for a countdown
    Code:
    ServertimeUrl = 'servertime.php?' + 1 * new Date();
    addToTimer = 0;
    
    lv = new LoadVars();
    lv.onData = function(v) {
     if (v != undefined) {
      addToTimer = 1000 * v - getTimer();
     }
    }
    lv.load(ServertimeUrl);
    
    oneHour = 3600000;
    
    onEnterFrame = function() {
     if (addToTimer) {
    
      serverTime = getTimer() + addToTimer;
      zeroHundred = 86400000 * Math.floor(serverTime / 86400000);
      todayEightAM = zeroHundred + 8 * oneHour;
      todayTenAM = zeroHundred + 10 * oneHour;
      tomorrowEightAM = zeroHundred + 32 * oneHour;
    
      if (serverTime < todayEightAM) {
       remaining = todayEightAM - serverTime; // offer that started yesterday
      } else if (serverTime > todayTenAM) {
       remaining = tomorrowEightAM - serverTime; // offer that started today
      } else {
       remaining = 0; // no offer at this time
      }
    
      if (remaining){
    
       remainingSeconds = Math.floor(remaining / 1000);
       remainingMinutes = Math.floor(remainingSeconds / 60);
       remainingHours = Math.floor(remainingMinutes / 60);
       remainingSeconds -= remainingMinutes * 60;
       remainingMinutes -= remainingHours * 60;
       
       txt1.text = 'Countdown : ' + remainingHours + 'h ';
       txt1.text += remainingMinutes + 'm ' + remainingSeconds + 's';
    
      } else {
       txt1.text = 'No offer at this time'; 
      }
    
     }
    }
    Last edited by w.brants; 11-09-2007 at 07:09 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center