dayjs.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * Day.js 配置
  3. * 配置 Day.js 所需的插件和本地化设置
  4. */
  5. import dayjs from 'dayjs';
  6. import 'dayjs/locale/zh-cn';
  7. // 导入插件 - 使用 require 方式避免 ESM 导入问题
  8. import weekday from 'dayjs/plugin/weekday';
  9. import localeData from 'dayjs/plugin/localeData';
  10. import weekOfYear from 'dayjs/plugin/weekOfYear';
  11. import weekYear from 'dayjs/plugin/weekYear';
  12. import advancedFormat from 'dayjs/plugin/advancedFormat';
  13. import customParseFormat from 'dayjs/plugin/customParseFormat';
  14. import quarterOfYear from 'dayjs/plugin/quarterOfYear';
  15. import timezone from 'dayjs/plugin/timezone';
  16. import utc from 'dayjs/plugin/utc';
  17. import isLeapYear from 'dayjs/plugin/isLeapYear';
  18. import duration from 'dayjs/plugin/duration';
  19. import relativeTime from 'dayjs/plugin/relativeTime';
  20. import isToday from 'dayjs/plugin/isToday';
  21. import isYesterday from 'dayjs/plugin/isYesterday';
  22. import isTomorrow from 'dayjs/plugin/isTomorrow';
  23. import isBetween from 'dayjs/plugin/isBetween';
  24. // 扩展插件
  25. dayjs.extend(weekday);
  26. dayjs.extend(localeData);
  27. dayjs.extend(weekOfYear);
  28. dayjs.extend(weekYear);
  29. dayjs.extend(advancedFormat);
  30. dayjs.extend(customParseFormat);
  31. dayjs.extend(quarterOfYear);
  32. dayjs.extend(timezone);
  33. dayjs.extend(utc);
  34. dayjs.extend(isLeapYear);
  35. dayjs.extend(duration);
  36. dayjs.extend(relativeTime);
  37. dayjs.extend(isToday);
  38. dayjs.extend(isYesterday);
  39. dayjs.extend(isTomorrow);
  40. dayjs.extend(isBetween);
  41. // 设置默认语言
  42. dayjs.locale('zh-cn');
  43. // 导出配置后的 dayjs
  44. export default dayjs;
  45. /**
  46. * 初始化 Day.js
  47. * 可在应用启动时调用此函数
  48. */
  49. export function initDayjs() {
  50. // 这里可以添加额外的初始化逻辑
  51. console.log('Day.js 已初始化,当前语言:', dayjs.locale());
  52. }