export function getDateToStrNum(date) {
 var year = date.getFullYear();
 var month = date.getMonth() + 1;
 var day = date.getDate();
 var hour = date.getHours();
 var minute = date.getMinutes();
 var second = date.getSeconds();
 return "" + year + formatDatePara(month) + formatDatePara(day);
}
function formatDatePara(str) {
 if (str.toString().length == 1) {
  return "0" + str;
 }
 return str;
}
function getDateToString_zhh(date) {
 var year = date.getFullYear();
 var month = date.getMonth() + 1;
 var day = date.getDate();
 var hour = date.getHours();
 var minute = date.getMinutes();
 var second = date.getSeconds();
 return year + "年" + formatDatePara(month) + "月" + formatDatePara(day) + "日 " + formatDatePara(hour) + ":" + formatDatePara(minute);
}

export function getDateToString_ymd(date) {
 var year = date.getFullYear();
 var month = date.getMonth() + 1;
 var day = date.getDate();
 var hour = date.getHours();
 var minute = date.getMinutes();
 var second = date.getSeconds();
 return year + "-" + formatDatePara(month) + "-" + formatDatePara(day);
}
export function GetMonday(dd, zj) {
 var week = dd.getDay(); //获取时间的星期数
 var minus = week ? week - zj : 6;
 dd.setDate(dd.getDate() - minus); //获取minus天前的日期
 var y = dd.getFullYear();
 var m = dd.getMonth() + 1; //获取月份
 var d = dd.getDate();
 return y + "-" + m + "-" + d;
}
export function addMonths(currentDate,monthNum){
 let lastDate = currentDate.setMonth(currentDate.getMonth() + 1 +monthNum);
 let date = new Date(lastDate);
 var year = date.getFullYear();
 var month = date.getMonth() + 1;
 var day = date.getDate();
 var hour = date.getHours();
 var minute = date.getMinutes();
 var second = date.getSeconds();
 return year + "-" + formatDatePara(month) + "-01";
 return getDateToString_ymd(new Date(lastDate));
}
export function getDateToString(date) {
 var year = date.getFullYear();
 var month = date.getMonth() + 1;
 var day = date.getDate();
 var hour = date.getHours();
 var minute = date.getMinutes();
 var second = date.getSeconds();
 return year + "-" + formatDatePara(month) + "-" + formatDatePara(day) + " " + formatDatePara(hour) + ":" + formatDatePara(minute) + ":" + formatDatePara(second);
}
export function padLeftStr(str, maxLength, fillStr) {
 if (typeof str !== "string") {
  str = str.toString()
 }
 let originStr = Math.floor(maxLength / fillStr.length)

 return (
     fillStr.repeat(originStr) +
     fillStr.slice(0, maxLength % fillStr) +
     str
 ).slice(str.length)
}
export function formatDateFun(chuo, fmt) {
 if (!chuo) {
  return ""
 }
 let dataTime = new Date(chuo)
 // console.log(dataTime.getFullYear())
 if (new RegExp(/(y+)/i).test(fmt)) {
  fmt = fmt.replace(
      RegExp.$1,
      String(dataTime.getFullYear()).slice(4 - RegExp.$1.length)
  )
 }
 let o = {
  "M+": dataTime.getMonth() + 1,
  "d+": dataTime.getDate(),
  "h+": dataTime.getHours(),
  "m+": dataTime.getMinutes(),
  "s+": dataTime.getSeconds()
 }
 for (let key in o) {
  if (new RegExp(`(${key})`).test(fmt)) {
   fmt = fmt.replace(RegExp.$1, padLeftStr(o[key], 2, "0"))
  }
 }
 return fmt
}