1 Reply Latest reply on Feb 7, 2012 10:26 AM by kglad

    Creating a CLOCK OFFSET option

    xcmuddman Level 1

      I am programming an instrument that has a feature for the user to offset the clock by the timezone that they are in. I have your basic clock functioning and give the users the ability to select their clock offset and store both the offset Hours and the Minutes in separate variables...

       

      My question is how to i take these variables and have them calculate/ update this standard clock function that i am using below:

       

      //clock offset variables:

      _global.ClockOffsetHRS;

      _global.ClockOffsetMINS;

       

      //Clock Code

      time=new Date(); // time object

      var seconds = time.getSeconds()

      var minutes = time.getMinutes()

      var hours = time.getHours()

      if (hours<12) {

      ampm = "am";

      }

      else{

      ampm = "pm";

      }

      while(hours >12){

      hours = hours - 12;

      }

      if(hours<10)

      {

      hours = " " + hours;

      }

      if(minutes<10)

      {

      minutes = "0" + minutes;

      }

      if(seconds<10)

      {

      seconds = "0" + seconds;

      }

      LCD_text_clock.text = hours + ":" + minutes + ":" + seconds //+ " " + ampm;

        • 1. Re: Creating a CLOCK OFFSET option
          kglad Adobe Community Professional & MVP

          use:

           

           

          //clock offset variables:

          _global.ClockOffsetHRS;

          _global.ClockOffsetMINS;

           

          //Clock Code <-the first part of this should not be in a loop.

          var time:Date=new Date();

           

          time=new Date(time.getTime()+ClockOffsetHRS*3600000+ClockOffsetMins*60000); // time object

          var seconds = time.getSeconds()

          var minutes = time.getMinutes()

          var hours = time.getHours()

          if (hours<12) {

          ampm = "am";

          }

          else{

          ampm = "pm";

          }

          while(hours >12){

          hours = hours - 12;

          }

          if(hours<10)

          {

          hours = " " + hours;

          }

          if(minutes<10)

          {

          minutes = "0" + minutes;

          }

          if(seconds<10)

          {

          seconds = "0" + seconds;

          }

          LCD_text_clock.text = hours + ":" + minutes + ":" + seconds //+ " " + ampm;

          1 person found this helpful