js時間格式轉換
格式化時間轉成時間戳
//格式化轉時間戳(單位秒) function strtotime(strtime) { strtime = strtime.substring(0, 19); strtime = strtime.replace(/-/g, '/'); strtime = new Date(strtime).getTime() / 1000; return strtime; }
時間戳轉格式化時間
//時間戳(單位秒)轉格式化 function getMyDate(str) { str = str * 1000; var oDate = new Date(str), oYear = oDate.getFullYear(), oMonth = oDate.getMonth() + 1, oDay = oDate.getDate(), oHour = oDate.getHours(), oMin = oDate.getMinutes(), oSen = oDate.getSeconds(), oTime = oYear + '-' + getzf(oMonth) + '-' + getzf(oDay) + ' ' + getzf(oHour) + ':' + getzf(oMin) + ':00'; //最后拼接時間 return oTime; };