//替换字符串
export function Replace(str, from, to) {
  return str.split(from).join(to);
}
// 日期类型格式成指定的字符串
export function FormatDate(date, format) {
  format = Replace(format, 'yyyy', date.getFullYear());
  format = Replace(format, 'MM', GetFullMonth(date));
  format = Replace(format, 'dd', GetFullDate(date));
  format = Replace(format, 'HH', GetFullHour(date));
  format = Replace(format, 'mm', GetFullMinute(date));
  format = Replace(format, 'ss', GetFullSecond(date));
  return format;
}
// js日期字符串转换成日期类型
export function parseDate(dateStr) {
  return new Date(Replace(dateStr, '-', '/'));
}
// 增加月
export function AddMonths(date, value) {
  date.setMonth(date.getMonth() + value);
  return date;
}
// 增加天
export function AddDays(date, value) {
  date.setDate(date.getDate() + value);
  return date;
}
// 增加时
export function AddHours(date, value) {
  date.setHours(date.getHours() + value);
  return date;
}
// 返回月份(两位数)
export function GetFullMonth(date) {
  var v = date.getMonth() + 1;
  if (v > 9) return v.toString();
  return '0' + v;
}

// 返回日(两位数)
export function GetFullDate(date) {
  var v = date.getDate();
  if (v > 9) return v.toString();
  return '0' + v;
}
// 返回时(两位数)
export function GetFullHour(date) {
  var v = date.getHours();
  if (v > 9) return v.toString();
  return '0' + v;
}
// 返回分(两位数)
export function GetFullMinute(date) {
  var v = date.getMinutes();
  if (v > 9) return v.toString();
  return '0' + v;
}
// 返回秒(两位数)
export function GetFullSecond(date) {
  var v = date.getSeconds();
  if (v > 9) return v.toString();
  return '0' + v;
}
