处理时间期限,两个时间相减

/**
* 转换时效
 * @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;
},

猜你喜欢

转载自blog.csdn.net/yxgd_1442962728/article/details/113250299