1. 程式人生 > >內置函數data時間格式轉換

內置函數data時間格式轉換

mon etsec 函數 second seconds else var 轉換 data

內置函數data時間格式轉換 function getDateString(date) { var year = date.getFullYear(); var month = date.getMonth() + 1; var day = date.getDate(); // 當月的幾號 var hour = date.getHours(); var min = date.getMinutes(); var sec = date.getSeconds();
// if(month<10){ // month = "0"+month; // }else { // month = month; // } month = month < 10 ? "0" + month : month; day = day < 10 ? "0" + day : day; hour = hour < 10 ? ‘0‘ + hour : hour; min = min < 10 ? "0" + min : min; sec = sec < 10 ? "0" + sec : sec; var str = year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec; console.log(str); } var date = new Date(); getDateString(date);

內置函數data時間格式轉換