Browse Source

时长显示分钟

lwx_v27
liwenxuan 1 month ago
parent
commit
7a3a9fcd22
  1. 38
      src/components/DesignForm/public/expand/datePicker.vue

38
src/components/DesignForm/public/expand/datePicker.vue

@ -40,7 +40,7 @@ const shichangShowFlag = computed(() => {
}
});
function calculateTimeDiff(startTimestamp: string, endTimestamp: string) {
/* function calculateTimeDiff(startTimestamp: string, endTimestamp: string) {
//
const start = parseInt(startTimestamp, 10);
const end = parseInt(endTimestamp, 10);
@ -70,6 +70,42 @@ function calculateTimeDiff(startTimestamp: string, endTimestamp: string) {
}
return `${days}${remainingHours} 小时`;
}
} */
function calculateTimeDiff(startTimestamp: string, endTimestamp: string) {
//
const start = parseInt(startTimestamp, 10);
const end = parseInt(endTimestamp, 10);
//
const diffMs = Math.abs(end - start);
//
const totalMinutes = Math.floor(diffMs / 60000);
//
const days = Math.floor(totalMinutes / 1440); // 1440 = 24
const remainingMinutesAfterDays = totalMinutes % 1440;
const hours = Math.floor(remainingMinutesAfterDays / 60);
const minutes = remainingMinutesAfterDays % 60;
//
let result = '';
if (days > 0) {
result += `${days}`;
}
if (hours > 0) {
result += `${hours} 小时 `;
}
if (minutes >= 0) { // 0
result += `${minutes} 分钟`;
}
return result.trim(); //
}
const valueFormat = "x";

Loading…
Cancel
Save