public.js 616 B

12345678910111213
  1. //1.格式化时间
  2. export function formatLocalDate(date) {
  3. const birthday = new Date(date); // 创建 Date 对象
  4. const year = birthday.getFullYear();
  5. const month = String(birthday.getMonth() + 1).padStart(2, '0'); // 月份从 0 开始,所以加 1
  6. const day = String(birthday.getDate()).padStart(2, '0');
  7. const hours = String(birthday.getHours()).padStart(2, '0');
  8. const minutes = String(birthday.getMinutes()).padStart(2, '0');
  9. const seconds = String(birthday.getSeconds()).padStart(2, '0');
  10. // 返回格式化后的字符串
  11. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  12. }