var newTime = new Date().getTime(); var oldTime = new Date().getTime(); //相差的毫秒數 var syhm = newTime - oldTime; var h = Math.floor(syhm%(24*60*60*1000)/(60*60*1000)) var m = Math.floor(syhm%(24*60*60*1000)%(60*60*1000)/(60*1000)); var s = Math.floor(syhm%(24*60*60*1000)%(60*60*1000)%(60*1000)/1000); h = h<10 ? '0'+h : h; m = m<10 ? '0'+m : m; s = s<10 ? '0'+s : s;