function EmsOnline (a, b, c, d) { var f = (c*60+d)-(a*60+b); return f % 60 >= 0.5? f+(1-(f%60)):f-(f%60); } alert(EmsOnline(14, 30, 16, 40));