Commit aa5f441c authored by jingnan's avatar jingnan 👀

增加计算两个日期时间字符串的时间差的方法

parent b686fd75
...@@ -1701,6 +1701,22 @@ export function addMinutes(date, minutes) { ...@@ -1701,6 +1701,22 @@ export function addMinutes(date, minutes) {
const resDate= formatDate(dateFormat, 'YYYY-MM-DD HH:mm:ss') const resDate= formatDate(dateFormat, 'YYYY-MM-DD HH:mm:ss')
return resDate return resDate
} }
/**
* 计算两个日期时间字符串的时间差(单位:分钟)
* @param {*} dateTimeStr1
* @param {*} dateTimeStr2
* @returns
*/
export function getTimeDifferenceInMinutes(dateTimeStr1, dateTimeStr2) {
const date1 = new Date(dateTimeStr1)
const date2 = new Date(dateTimeStr2)
if (isNaN(date1.getTime()) || isNaN(date2.getTime())) {
throw new Error('无效的日期时间字符串')
}
const differenceInMilliseconds = Math.abs(date2 - date1) // 使用Math.abs获取绝对值,确保总是正数
const differenceInSeconds = differenceInMilliseconds / (1000 * 60)
return differenceInSeconds
}
export default { export default {
findByNameVnode, findByNameVnode,
...@@ -1795,5 +1811,6 @@ export default { ...@@ -1795,5 +1811,6 @@ export default {
subNum, subNum,
getTargetJobResponses, getTargetJobResponses,
export_excel, export_excel,
addMinutes addMinutes,
getTimeDifferenceInMinutes
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment