date.js 779 B

1234567891011121314151617181920212223242526
  1. import dayjs from "@/plugin/dayjs/dayjs.min.js";
  2. /**
  3. * 获得当前周的开始和结束时间
  4. */
  5. export function getWeekTimes() {
  6. const today = new Date();
  7. const dayOfWeek = today.getDay();
  8. return [
  9. new Date(today.getFullYear(), today.getMonth(), today.getDate() - dayOfWeek, 0, 0, 0),
  10. new Date(today.getFullYear(), today.getMonth(), today.getDate() + (6 - dayOfWeek), 23, 59, 59)
  11. ]
  12. }
  13. /**
  14. * 获得当前月的开始和结束时间
  15. */
  16. export function getMonthTimes() {
  17. const today = new Date();
  18. const year = today.getFullYear();
  19. const month = today.getMonth();
  20. const startDate = new Date(year, month, 1, 0, 0, 0);
  21. const nextMonth = new Date(year, month + 1, 1);
  22. const endDate = new Date(nextMonth.getTime() - 1);
  23. return [startDate, endDate]
  24. }