1. 程式人生 > 其它 >處理時間期限,兩個時間相減

處理時間期限,兩個時間相減

技術標籤:vuejsjavascriptvue.jshtml5

/**
* 轉換時效
 * @creatTime creatTime 建立時間 時間戳
 * @param time 時效 20天
 */
dateTimes(creatTime,time){
    var timestamp = Date.parse(new Date());//當前時間
    var times = creatTime+(time*1000*60*60*24);
    var runTime = parseInt((times- timestamp)/1000);
    var year = Math.floor(runTime /
86400 / 365); runTime = runTime % (86400 * 365); var month = Math.floor(runTime / 86400 / 30); runTime = runTime % (86400 * 30); var day = Math.floor(runTime / 86400); runTime = runTime % 86400; var hour = Math.floor(runTime / 3600); year = year>0?year+'年':''; month = month>0?month+'月'
:'' day = day>0?day+'天':'' hour = hour>0?hour+'小時':''   return year+month+day+hour; },