2
그래서 나는 내가 버스가 도착할 때까지 기다려야 할 시간을 결정하는 함수를 만들어 잘못된 답을주는 계산기를 :시간이-에
function arrival(arrtime){
//convert to seconds
function toSeconds(time_str) {
// Extract hours, minutes and seconds
var parts = time_str.split(':');
// compute and return total seconds
return (parts[0] * 3600) + (parts[1] * 60) + parts[2];// seconds
}
var a = new Date().getHours() + ":" + new Date().getMinutes() + ":" + new Date().getSeconds();//current time
var difference = toSeconds(arrtime) - toSeconds(a);
function sformat(s) {
var fm = [
Math.floor(s/60/60/24), // DAYS
Math.floor(s/60/60) % 24, // HOURS
Math.floor(s/60) % 60, // MINUTES
s % 60 // SECONDS
];
return $.map(fm, function(v, i) { return ((v < 10) ? '0' : '') + v; }).join(':');
}
if (difference > 0){
result = sformat(difference);
} else if (difference < 1 && difference > -20) {
result = "Chegou!";
} else if (difference <= -20) {
result = "Amanhã às " + arrtime;
}
return result;
}
//usage example:
arrival("16:30:00");
를하지만 나에게 잘못된 대답을주고 .... 몇 가지 계산을 수행해야합니다 틀렸어.하지만 내 인생에서 나는 그것을 알아낼 수 없다!
트릭을 한 것은 감사합니다! –