时间格式转化和计算时间差

//标准时间转年月日时分秒时间格式
function formatDateTime(date) {
  let y = new Date(date).getFullYear();
  let m = new Date(date).getMonth() + 1;
  m = m < 10 ? "0" + m : m;
  let d = new Date(date).getDate();
  d = d < 10 ? "0" + d : d;
  let h = new Date(date).getHours();
  h = h < 10 ? "0" + h : h;
  let minute = new Date(date).getMinutes();
  minute = minute < 10 ? "0" + minute : minute;
  let second = new Date(date).getSeconds();
  second = second < 10 ? "0" + second : second;
  return y + "-" + m + "-" + d + " " + h + ":" + minute + ":" + second;
};
//标准时间格式,计算时间差->多少分钟
function standardGetInervalMinute(startDate, endDate) {
  let ms = new Date(endDate).getTime() - new Date(startDate).getTime();
  return ms / 1000 / 60;
};

猜你喜欢

转载自www.cnblogs.com/XUYIYUAN/p/11297972.html