<script type="text/javascript">
import Vue from "vue";
//把秒转成 几天几小时
const   getDuration=function(second) {
    var days = Math.floor(second / 86400);
    var hours = Math.floor((second % 86400) / 3600);
    var minutes = Math.floor(((second % 86400) % 3600) / 60);
    var seconds = Math.floor(((second % 86400) % 3600) % 60);
    var duration = days + "天" + hours + "小时" + minutes + "分" ;// seconds + "秒";

    if (days > 0) {
        return duration;
    }
    if (hours > 0) {
        return hours + "小时" + minutes + "分";
    } 
     if(minutes>0){
        return minute + "分"
    }

    return second + "秒" ;
}

//获取两个日期相差多少Date格式 var date2 = new Date("2020-11-10 12:00:00");
const getDayComper=function (date1, date2) {
  
    var ms = Math.abs(date2 - date1);
    // 两个日期相减得到毫秒数  1s=1000ms
    var s = ms / 1000; // 毫秒转为秒
    var day = Math.floor(s / 3600 / 24); //天
    var hour = Math.floor(s / 3600 % 24); //小时
    var minute = Math.floor(s % 60);  //分
    if (day > 0) {
        return day + "天" + hour + "小时" + minute + "分";
    }
    if (hour>0) {
        return hour + "小时" + minute + "分";
    }
    if(minute>0){
        return minute + "分"
    }

    return s + "秒";
}

//获取当前日期
const getNowDate= function () {
    var d = new Date();
    var year = d.getFullYear();
    var month = d.getMonth() + 1;
    var day = d.getDate();
    var dateStr = year + '-' + getFormatDate(month) + '-' + getFormatDate(day);
    return dateStr;
}
 
 

export default {
    getDuration,
    getDayComper,
    getNowDate,
    
};
</script>