1. 程式人生 > >用javascript在頁面中顯示系統時間

用javascript在頁面中顯示系統時間

//把毫秒數轉化成固定格式的日期
var time = new Date(po.replyTime); 
var year = time.getFullYear();
var month = time.getMonth()+1;
var day = time.getDate();
var hour = time.getHours();
var minute = time.getMinutes();
var second = time.getSeconds();
if (month.toString().length == 1){month = "0" + month;}
   if (day.toString().length == 1){day = "0" + day;}
   if (hour.toString().length == 1){hour = "0" + hour;}
   if (minute.toString().length == 1){ minute = "0" + minute;}
   if (second.toString().length == 1){ second = "0" + second;}
html=year+"-"+month+"-"+day;
}
return html;