export function getFMdate(number, separator) {
  const n = parseInt(number);
  const nd = new Date();
  const day = nd.getDate();
  const setd = new Date(nd.setDate(day + n));
  const ryear = setd.getFullYear();
  const rmonth = setd.getMonth() + 1;
  const rday = setd.getDate();
  let frmonth, frday;
  // month day + '0'
  if (rmonth < 10) {
    frmonth = '0' + rmonth;
  } else {
    frmonth = rmonth;
  }
  if (rday < 10) {
    frday = '0' + rday;
  } else {
    frday = rday;
  }
  // separator
  const sep = separator ? separator : '-';
  return ryear + sep + frmonth + sep + frday;
}

export function getDate(time = '') {
  var now = new Date();
  if (time != '') {
    now = new Date(time);
  }
  const year = now.getFullYear(); //得到年份
  let month = now.getMonth(); //得到月份
  let date = now.getDate(); //得到日期
  month = month + 1;
  month = month.toString().padStart(2, '0');
  date = date.toString().padStart(2, '0');
  return `${year}-${month}-${date}`;
}
export function getDate1(time = '') {
  var now = new Date();
  if (time != '') {
    now = new Date(time);
  }
  const year = now.getFullYear(); //得到年份
  let month = now.getMonth(); //得到月份
  month = month + 1;
  month = month.toString().padStart(2, '0');
  return `${year}-${month}`;
}

export function getDate2(time = '') {
  var now = new Date();
  if (time != '') {
    now = new Date(time);
  }
  const year = now.getFullYear(); //得到年份
  return `${year}`;
}

//获取前几天时间
export function getPastTime(month) {
  const time = new Date();
  const yy = time.getFullYear(); //获取完整的年份(4位,1970-???)
  const M = time.getMonth() + 1; //获取当前月份(0-11,0代表1月),
  const d = time.getDate(); //获取当前日(1-31)
  // 获取指定的过去时间
  const past = M - month;
  const pastM = past < 0 ? past + 12 : past > 10 ? past : '0' + past;
  // 小于9的，在前面加0
  const MM = M > 9 ? M : '0' + M;
  const dd = d > 9 ? d : '0' + d;
  // 指定的过去时间
  const PastTime = yy + '-' + pastM + '-' + dd;
  // 当前时间
  const nowTime = yy + '-' + MM + '-' + dd;
  return [PastTime, nowTime];
}
export function getPastTime1() {
  const today = new Date();
  const yy = today.getFullYear(); //获取完整的年份(4位,1970-???)
  const M = today.getMonth() + 1; //获取当前月份(0-11,0代表1月),
  const d = today.getDate(); //获取当前日(1-31)
  const previousDay = new Date(today);
  previousDay.setDate(today.getDate() - 1);
  const year = previousDay.getFullYear();
  const month = (previousDay.getMonth() + 1).toString().padStart(2, '0');
  const day = previousDay.getDate().toString().padStart(2, '0');
  // 小于9的，在前面加0
  const MM = M > 9 ? M : '0' + M;
  const dd = d > 9 ? d : '0' + d;
  // 指定的过去时间
  const PastTime = year + '-' + month + '-' + day;
  // 当前时间
  const nowTime = yy + '-' + MM + '-' + dd;
  return [PastTime, nowTime];
}
// 时间戳转换日期格式方法
export function formatDateTime(value) {
  var date = new Date();
  if (value != '') {
    date = new Date(value);
  }
  const y = date.getFullYear(); // 年
  let MM = date.getMonth() + 1; // 月
  MM = MM < 10 ? '0' + MM : MM;
  let d = date.getDate(); // 日
  d = d < 10 ? '0' + d : d;
  let h = date.getHours(); // 时
  h = h < 10 ? '0' + h : h;
  let m = date.getMinutes(); // 分
  m = m < 10 ? '0' + m : m;
  let s = date.getSeconds(); // 秒
  s = s < 10 ? '0' + s : s;
  return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
}
