質問


私は初心者で、ウルヘビーが必要です。日、時間、分、秒の発見に問題があります。数秒後に数分後に何を更新するかわからない。
日/数時間/分/秒の形式で特定の日付にカウントダウンしようとしています。
これまでのもののリンクです。
THNX事前に!:)

役に立ちましたか?

解決

count_execution関数を修正し、いくつかのコメントを追加しました。それはあなたが尋ねるものをするべきです。

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);
}
.

それが役立つことを願っています。

他のヒント

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);
.

これは?

また、必ず確認してください。多分あなたはそこにいくつかのインスピレーションを得ることができます。

トリックを行うために利用可能な多くのプラグインの1つを使用しないのは、次のリンクを検討してください:

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

これは同じ目的のために多くのプラグインをリストしています、それらのいずれかを使って笑顔を使っています:) http://www.tripwiremagazine.com/2012/01/jquery-countdown.-scripts.html

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top