tj
2025-06-05 bba272999cc546f65781bf3d20245a3f819af67f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
 
/**
 * 
 * 获取当天日期
 * @returns  YYYY-MM-DD 格式
 */
export function getDefaultDate() {
    const today = new Date();
    const year = today.getFullYear();
    const month = String(today.getMonth() + 1).padStart(2, '0');
    const day = String(today.getDate()).padStart(2, '0');
    const now = `${year}-${month}-${day}`;
    return now
  }
  
  /**
   * 
   * 获取昨天日期
   * @returns   YYYY-MM-DD 格式
   */
  export function getYesterdayDate() {
    const today = new Date();
    const yesterday = new Date(today);
    yesterday.setDate(yesterday.getDate() - 1);
  
    const year = yesterday.getFullYear();
    const month = String(yesterday.getMonth() + 1).padStart(2, '0');
    const day = String(yesterday.getDate()).padStart(2, '0');
  
    const yesterdayDate = `${year}-${month}-${day}`;
    return yesterdayDate;
  }
  
  /**
   * 获取本周的开始时间和结束日期
   * @returns   YYYY-MM-DD 格式的开始时间和结束时间
   */
  export function getStartAndEndOfWeek() {
   
    const today = new Date();
    const currentDayOfWeek = today.getDay(); // 0 (Sunday) to 6 (Saturday)
  
    const startDate = new Date(today);
    startDate.setDate(today.getDate() - currentDayOfWeek + 1);
  
    const endDate = new Date(today);
    endDate.setDate(today.getDate() + (6 - currentDayOfWeek + 1));
  
    const startYear = startDate.getFullYear();
    const startMonth = String(startDate.getMonth() + 1).padStart(2, '0');
    const startDay = String(startDate.getDate()).padStart(2, '0');
    const endYear = endDate.getFullYear();
    const endMonth = String(endDate.getMonth()+1).padStart(2, '0');
    const endDay = String(endDate.getDate()).padStart(2, '0');
  
    const startOfWeek = `${startYear}-${startMonth}-${startDay}`;
    const endOfWeek = `${endYear}-${endMonth}-${endDay}`;
  
    return { startOfWeek, endOfWeek };
  }
  
  
  /**
   * 
   * 获取前一周的 开始时间和结束日期
   * @returns  YYYY-MM-DD 格式的开始时间和结束时间
   */
  export function getPreviousWeekDates() {
    const today = new Date();
    const currentDay = today.getDay(); // 0 (Sunday) to 6 (Saturday)
  
    const startDate = new Date(today);
    startDate.setDate(today.getDate() - currentDay - 6); // Start from last Sunday
  
    const endDate = new Date(today);
    endDate.setDate(today.getDate() - currentDay); // End on last Saturday
  
    const startYear = startDate.getFullYear();
    const startMonth = String(startDate.getMonth() + 1).padStart(2, '0');
    const startDay = String(startDate.getDate()).padStart(2, '0');
  
    const endYear = endDate.getFullYear();
    const endMonth = String(endDate.getMonth() + 1).padStart(2, '0');
    const endDay = String(endDate.getDate()).padStart(2, '0');
  
    const startDateString = `${startYear}-${startMonth}-${startDay}`;
    const endDateString = `${endYear}-${endMonth}-${endDay}`;
  
    return { startDate: startDateString, endDate: endDateString };
  }
 
 
  /**
   * 获取今天是周几
   */
  export function getDayOfWeek(){
    const daysOfWeek = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
    const today = new Date();
    const dayOfWeekNumber = today.getDay();
    const dayOfWeek = daysOfWeek[dayOfWeekNumber];
    return dayOfWeek;
  }
 
 
  /**
   * 
   * 获取上周五的日期
   * @returns  返回上周五的yyyy-MM-dd格式
   */
  export function getPreviousFriday() {
    const today = new Date();
    const currentDay = today.getDay(); // 0 for Sunday, 1 for Monday, ..., 6 for Saturday
  
    const daysUntilFriday = (currentDay + 2) % 7; // Calculate days until previous Friday
    const previousFriday = new Date(today); // Create a copy of the current date
    previousFriday.setDate(today.getDate() - daysUntilFriday); // Subtract days to get previous Friday
  
    const year = previousFriday.getFullYear();
    const month = String(previousFriday.getMonth() + 1).padStart(2, '0');
    const day = String(previousFriday.getDate()).padStart(2, '0');
  
    return `${year}-${month}-${day}`;
  }