leon 1 year ago
parent
commit
b83b5aff39
1 changed files with 17 additions and 0 deletions
  1. 17 0
      src/utils/time_format.ts

+ 17 - 0
src/utils/time_format.ts

@@ -723,6 +723,23 @@ export class TimeFormatter {
     return timestamp
   }
 
+  static getSundayTimestamp = () => {
+    const now = new Date();
+    const currentDay = now.getDay(); // Get the current day of the week (0 for Sunday, 1 for Monday, etc.)
+    const startOfWeek = new Date(now); // Create a new Date object with the current date and time
+
+    // Calculate the difference in milliseconds to the beginning of the week
+    const diffToMonday = currentDay * 24 * 60 * 60 * 1000; // Subtract 1 day worth of milliseconds for each day after Monday
+
+    startOfWeek.setTime(now.getTime() - diffToMonday); // Set the time to the beginning of the week (Monday at 00:00:00)
+    startOfWeek.setHours(0)
+    startOfWeek.setMinutes(0)
+    startOfWeek.setSeconds(0)
+    startOfWeek.setMilliseconds(0)
+    const timestamp = startOfWeek.getTime(); // Get the timestamp in milliseconds
+    return timestamp
+  }
+
   //hh:mm转换成秒数
   static timestringToSeconds = (strTime: string) => {
     var list = strTime.split(':')