js時間轉換
阿新 • • 發佈:2018-01-06
int ntb body minute spa string nth subst nbsp
window.onload=function(){ setInterval("mytime()",1000); } function mytime(){ document.getElementById("time").innerHTML = fmtDate(new Date()); } function fmtDate(obj){ var date = new Date(obj); var y = 1900+date.getYear(); var m = "0"+(date.getMonth()+1); var d = "0"+date.getDate();var h = "0"+date.getHours(); var min = "0"+date.getMinutes(); var s = "0"+date.getSeconds(); return y+"年-"+m.substring(m.length-2,m.length)+"月-"+d.substring(d.length-2,d.length)+"日-"+h.substring(h.length-2,h.length)+"時-"+min.substring(min.length-2,min.length)+"分-"+s.substring(s.length-2,s.length)+‘秒‘; }
js時間轉換