
/**
 * 时间格式化函数
 * @param {Date|string|number} date - 可接受Date对象/时间戳/ISO字符串
 * @returns {string} 格式为"yyyy-mm-dd hh:mm:ss"的时间字符串
 */
export function formatDateTime(date) {
  const d = date instanceof Date ? date : new Date(date);

  const pad = n => n.toString().padStart(2, '0');

  return [
    d.getFullYear(),
    pad(d.getMonth() + 1),
    pad(d.getDate())
  ].join('-') + ' ' + [
    pad(d.getHours()),
    pad(d.getMinutes()),
    pad(d.getSeconds())
  ].join(':');
}
