저는 초보자이며 도움이 필요합니다. 나는 일,시, 분, 초를 알아 내는데 문제가있다. 초가 60에 도달하고 몇 시간과 며칠 후에도 몇 분 후에 업데이트 할 지 모릅니다.
일 /시/분/초 형식으로 주어진 날짜로 카운트 다운하려고합니다.
Here is the link of what I've done so far.
미리 Thnx! :)jQuery에서 카운트 다운 기능 만들기
답변
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);
}
희망이 있습니다.
예, 제가 원했던 것이 있습니다. 그러나 jQuery를 사용하여 몇 분, 몇 초만에 쉽게 얻을 수있는 방법이 있습니까? – FoxKllD
아마도 @Mohammed와 같은 jQuery 플러그인을 사용하는 것이 가장 좋습니다. 엄밀히 말하면 날짜 조작 및 형식화에 관해서는 최근에 [Moment.js] (http://momentjs.com)를 발견했으며 나에게 매우 유용했습니다. –
이유를 고려, 트릭을 할 수있는 다양한 플러그인 중 하나를 사용하지 않는 다음 링크 :
http://keith-wood.name/countdown.html이 하나가 같은 목적을 위해 많은 플러그인을 나열한다
, 하나를 사용하여 그 중이 할 것 http://www.tripwiremagazine.com/2012/01/jquery-countdown-scripts.html
자원을 제공해 주셔서 감사합니다! – FoxKllD
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);
:) 미소?
this도 확인하시기 바랍니다. 어쩌면 거기에서 영감을 얻을 수 있습니다.
프로그래밍 문제가 아닌 수학 문제 인 것 같습니다. – benck