export function dateFormat(timedate) {
  if (timedate === null || timedate === undefined) {
    return "";
  } else {
    let arr;
    // 首先对日期进行拆解，获得日期字符串
    if (timedate.indexOf("T") > -1) {
      arr = timedate.split("T");
    } else {
      arr = timedate.split(" ");
    }
    var d = arr[0];
    var darr = d.split("-");
    var t = arr[1];
    var tarr = t.split(".000");
    var marr = tarr[0].split(":");
    var dd =
      parseInt(darr[0]) +
      "/" +
      parseInt(darr[1]) +
      "/" +
      parseInt(darr[2]) +
      " " +
      parseInt(marr[0]) +
      ":" +
      parseInt(marr[1]) +
      ":" +
      parseInt(marr[2]);

    const date = new Date(Date.parse(dd));
    date.setTime(date.setHours(date.getHours() + 8));

    var year = date.getFullYear();
    /* 在日期格式中，月份是从0开始的，因此要加0
     * 使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
     * */
    var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
    var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
    // var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
    // var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
    // var seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
    // 拼接
    // return (year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds)
    return year + "-" + month + "-" + day;
  }
}
export function getNowDate() {
  var date = new Date();
  var year = date.getFullYear();
  var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
  var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
  return year + "-" + month + "-" + day;
}
export function dateTimeFormat(time) {
  var date = new Date(time);
  var year = date.getFullYear();
  var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
  var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
  var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
  var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
  var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
  return `${year}-${month}-${day}` + `  ` + `${hours}:${minutes}:${seconds}`;
}
