//毫秒时间转换为yyyy-MM-dd
export const msToDateString = function (ms) {
  let date = new Date(ms);
  let year = date.getFullYear();
  let month = date.getMonth() + 1;
  let day = date.getDate();
  if (month < 10) {
    month = "0" + month;
  }
  if (day < 10) {
    day = "0" + day;
  }
  return year + "-" + month + "-" + day;
};
// 秒时间转换为yyyy-MM-dd HH:mm:ss
export const dateFormat = function (unixtimestamp) {
  unixtimestamp = new Date(unixtimestamp * 1000);
  let year = 1900 + unixtimestamp.getYear();
  let month = "0" + (unixtimestamp.getMonth() + 1);
  let date = "0" + unixtimestamp.getDate();
  let hour = "0" + unixtimestamp.getHours();
  let minute = "0" + unixtimestamp.getMinutes();
  let second = "0" + unixtimestamp.getSeconds();
  return (
    year +
    "-" +
    month.substring(month.length - 2, month.length) +
    "-" +
    date.substring(date.length - 2, date.length) +
    " " +
    hour.substring(hour.length - 2, hour.length) +
    ":" +
    minute.substring(minute.length - 2, minute.length) +
    ":" +
    second.substring(second.length - 2, second.length)
  );
};
// 读取url参数
export const getQueryletiable = function (letiable) {
  let query = window.location.search.substring(1);
  query = decodeURI(query);
  let lets = query.split("&");
  for (let i = 0; i < lets.length; i++) {
    let pair = lets[i].split("=");
    if (pair[0] === letiable) {
      return pair[1];
    }
  }
  return false;
};
// 通过日期获取秒数
export const getSecondsFromDate = function (date) {
  let _ms = new Date(date).getTime();
  return parseInt(_ms / 1000);
};
