import moment from 'moment'
// 计算时间差
export function getGapTimes(startTime, endTime) {startTime = new Date(moment(startTime))
endTime = endTime ? new Date(endTime) : new Date()
let start = Date.parse(startTime)
let end = Date.parse(endTime)
// 开始工夫转文本格式
let start_ymd = Date.parse(startTime.getFullYear() +
'/' +
(startTime.getMonth() + 1) +
'/' +
startTime.getDate())
// 完结工夫转文本格式
let end_ymd = Date.parse(endTime.getFullYear() +
'/' +
(endTime.getMonth() + 1) +
'/' +
endTime.getDate())
// day_1 单纯的天数差
// day_2 查看是否是明天日期,是为 0。输入天数差。let day_1, day_2, hour, minute, second
let result_1 = start < end ? end - start : start - end
let result_2 = start_ymd - end_ymd
day_1 = Math.floor(result_1 / (3600 * 24 * 1000))
day_2 = start_ymd == end_ymd ? 0 : Math.floor(result_2 / (3600 * 24 * 1000))
hour = Math.floor((result_1 % (3600 * 24 * 1000)) / (3600 * 1000))
minute = Math.floor((result_1 % (3600 * 1000)) / (60 * 1000))
second = Math.floor((result_1 % (60 * 1000)) / 1000)
return {day_1, day_2, hour, minute, second}
}
// 金额格式化
export function memonyFormat(memony) {let splitMemony = String(memony).split('.')
let integerM = splitMemony[0]
let decimalM = splitMemony[1] || '00'
let IM = ''
decimalM = decimalM.slice(0, 2)
integerM = integerM.split('').reverse().join('')
IM = integerM.replace(/D/g, '').replace(/...(?!$)/g,'$&,')
IM = IM.split('').reverse().join('')
return IM + '.' + decimalM
}
// 银行卡号格式化
export function bankAmountFormat(amount) {return amount.replace(/D/g, '').replace(/....(?!$)/g,'$& ')
}
继续更新 ing…