Domanda


I Am Newbie e ho bisogno di un aiuto.Ho un problema per trovare giorni, ore, minuti e secondi.Non so cosa aggiornare minuti dopo che i secondi raggiungeranno 60 e lo stesso con ore e giorni.
Sto cercando di contare alla rovescia per una data data in un formato di giorni / ore / minuti / secondi.
Ecco il link di quello che ho fatto finora.
Thnx in anticipo!:)

È stato utile?

Soluzione

Ho modificato la funzione count_execution e ha aggiunto alcuni commenti.Dovrebbe fare ciò che chiedi.

function count_execution() {
  // target date of event
  var eventDate   = new Date(settings.date);
  // now
  var currentDate = new Date();
  // get date diff *in milliseconds*
  var diff   = Math.abs(currentDate - eventDate);

  // compute days left
  // 24h * 60m * 60s * 1000 = 86400000
  var days = Math.floor(diff / 86400000);
  diff = diff % 86400000;

  // compute hours left
  // 60m * 60s * 1000 = 3600000
  var hours = Math.floor(diff / 3600000);
  diff = diff % 3600000;

  // the same for minutes
  var minutes = Math.floor(diff / 60000);
  diff = diff % 60000;

 // finally, seconds
 var seconds = Math.floor(diff / 1000);

 $this.find('#days').text(days);
 $this.find('#hours').text(hours);
 $this.find('#mins').text(minutes);
 $this.find('#secs').text(seconds);
}
.

Spero che aiuti.

Altri suggerimenti

var seconds = 1355998990 - new Date().getTime(), // whatever
minutes = Math.floor(seconds/60),
hours = Math.floor(minutes/60),
days = Math.floor(hours/24);

seconds %= 60;
minutes %= 60;
hours %= 24;

console.log("d: " + days + " h: " + hours + " m: " + minutes + " s: " + seconds);
.

lo farà?

Assicurati anche di controllare questo ;Forse puoi avere qualche ispirazione lì.

Perché non usi uno dei tanti plugin disponibili per fare il trucco, considera i seguenti collegamenti:

http://keith-wood.name/countdown.html

Questo sta elencando molti plugin per lo stesso scopo, usa qualcuno e sorridi :) http://www.tripwiremagazine.com/2012/01/jquery-countdown-scripts.html

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top