export const formatDate = (time: any, type = '-') => {// 格式化日期yyyy-MM-dd
  const Dates = new Date(time);
  const year: number = Dates.getFullYear();
  const month: any = (Dates.getMonth() + 1) < 10 ? '0' + (Dates.getMonth() + 1) : (Dates.getMonth() + 1);
  const day: any = Dates.getDate() < 10 ? '0' + Dates.getDate() : Dates.getDate();
  return year + type + month + type + day;
};
export const formatDateTime = (dateTime: any) => { // 格式化yyyy-MM-dd HH:mm:ss
  const date = new Date(dateTime)
  const y = date.getFullYear()
  let m: string | number = date.getMonth() + 1
  m = m < 10 ? `0${String(m)}` : m
  let d: string | number = date.getDate()
  d = d < 10 ? `0${String(d)}` : d
  let h: string | number = date.getHours()
  h = h < 10 ? `0${String(h)}` : h
  let minute: string | number = date.getMinutes()
  minute = minute < 10 ? `0${String(minute)}` : minute
  let second: string | number = date.getSeconds()
  second = second < 10 ? `0${String(second)}` : second
  return `${String(y)}-${String(m)}-${String(d)}   ${String(h)}:${String(
    minute
  )}:${String(second)}`
}

/**
 * 判断是否为这个格式2023-09-07 08:00:00
 * @param strDate 
 * @returns 
 */
export function strFormatDateTime(strDate?: string) {
  if (!strDate) return
  const strDateArr = strDate.split(" ")
  const newStrDate = strDateArr.length !== 2 ? formatDateTime(`${strDate} 00:00:00`) : strDate
  return newStrDate
}

/**
 * 获取当前时间年月日时分秒
 * @returns
 */
export function getCurrentDateTime(hoursTag = ':') {
  const now = new Date();
  const year = now.getFullYear(); // 获取当前年份
  let month: any = now.getMonth() + 1; // 获取当前月份（注意：月份从0开始，需要加1）
  let day: any = now.getDate(); // 获取当前日期
  let hours: any = now.getHours(); // 获取当前小时
  let minutes: any = now.getMinutes(); // 获取当前分钟
  let seconds: any = now.getSeconds(); // 获取当前秒钟
  // 如果月、日、小时、分钟、秒钟小于10，在前面补0
  if (month < 10) {
    month = '0' + month;
  }
  if (day < 10) {
    day = '0' + day;
  }
  if (hours < 10) {
    hours = '0' + hours;
  }
  if (minutes < 10) {
    minutes = '0' + minutes;
  }
  if (seconds < 10) {
    seconds = '0' + seconds;
  }
  const datetime = year + '-' + month + '-' + day + ' ' + hours + hoursTag + minutes + hoursTag + seconds;
  return datetime;
}