// 补0
export function add0(m) {
  return m < 10 ? "0" + m : m;
}
// 倒计时
export function djTime(data) {
  return add0(parseInt(data/60))+':'+add0(data%60);
}

export function formatTime(data) {
  var time = new Date(data);
  var y = time.getFullYear();
  var m = time.getMonth() + 1;
  var d = time.getDate();
  var h = time.getHours();
  var mm = time.getMinutes();
  var ss = time.getSeconds();
  return (y + "-" + add0(m) + "-" + add0(d) + " " + add0(h) + ":" + add0(mm) + ":" + add0(ss));
}
//计算两个时间之间的时间差 多少天时分秒
export function intervalTime(startTime, endTime) {
  var stime = new Date(startTime);
  var etime = new Date(endTime);
  if(stime > etime){
    return add0(0)+':'+add0(0)
  }
  var y = etime.getFullYear() - stime.getFullYear();
  var m = etime.getMonth() + 1 - (stime.getMonth() + 1);
  var d = etime.getDate() - stime.getDate();
  var h = etime.getHours() - stime.getHours();
  var mm = etime.getMinutes() - stime.getMinutes();
  var ss = etime.getSeconds() - stime.getSeconds();
  var time = y*365*24*60*60 + m*30*24*60*60 + d*24*60*60 + h*60*60 + mm*60 + ss
  time = add0(parseInt(time/60))+':'+add0(time%60)
  return time;
}
