2010-09-13 16 views

Respuesta

20

No puede obtener directamente los segundos restantes del temporizador. Puede guardar en una variable la marca de tiempo cuando se crea el temporizador y usarlo para calcular el tiempo hasta la siguiente ejecución.

muestra:

var startTimeMS = 0; // EPOCH Time of event count started 
var timerId;   // Current timer handler 
var timerStep=5000; // Time beetwen calls 

// This function starts the timer 
function startTimer(){ 
    startTimeMS = (new Date()).getTime(); 
    timerId = setTimeout("eventRaised",timerStep); 
} 


// This function raises the event when the time has reached and 
// Starts a new timer to execute the opeartio again in the defined time 
function eventRaised(){ 

    alert('WOP EVENT RAISED!'); 

    clearTimer(timerId); // clear timer 
    startTimer(); // do again 
} 

// Gets the number of ms remaining to execute the eventRaised Function 
function getRemainingTime(){ 
    return timerStep - ((new Date()).getTime() - startTimeMS); 
} 
  • Esto es código de ejemplo personalizado creado "sobre la marcha".
4

No es posible, pero si configura el contenido de una var por separado a la hora que lo configuró, puede averiguarlo fácilmente de forma manual.

Cuestiones relacionadas