爲什麼不會季度時間告訴我1,2,3,4?或所有的數字? 即時試圖讓每15分鐘。季度時間不會準確
是nextlaunch不計算下15分鐘吧?
爲什麼不用它計算正確的下15分鐘?
我希望它四分之一小時輸出所有的15分鐘。
X:15 = 1
X:30 = 2
X:45 = 3
X:00 = 4 or 0
目前的結果:
4/9/2016 @ 18:30:0
fiddle.jshell.net/:60 2
fiddle.jshell.net/:59 4/9/2016 @ 18:30:0
fiddle.jshell.net/:60 2
fiddle.jshell.net/:59 4/9/2016 @ 18:30:0
fiddle.jshell.net/:60 2
fiddle.jshell.net/:59 4/9/2016 @ 19:0:0
fiddle.jshell.net/:60 0
小提琴:https://jsfiddle.net/g2x1jmzb/
代碼:
var y = 1;
while(y <= 4) {
var interval = (900000 * y);
var nextlaunch = new Date(Math.ceil(new Date().getTime()/interval)*interval);
var datetime = "" + nextlaunch.getDate() + "/"
+ (nextlaunch.getMonth()+1) + "/"
+ nextlaunch.getFullYear() + " @ "
+ nextlaunch.getHours() + ":"
+ nextlaunch.getMinutes() + ":"
+ nextlaunch.getSeconds();
quarterHours = Math.round(nextlaunch.getMinutes()/15);
console.log(datetime);
console.log(quarterHours);
y++;
}
你期望什麼? –
歡迎來到Stack Overflow!請參考[遊覽],四處看看,並仔細閱讀[幫助],尤其是[*我如何提出一個好問題?](/ help/how-to-ask) –
我會期待nextlaunch有時間爲4個未來15分鐘, ,但在這種情況下,應該是4個半小時。 15 = 1 30 = 2 45 = 3 00 = 4/0 但這不起作用 – user3199857