邓雄飞 4 years ago
parent
commit
1151b7d7dc
1 changed files with 11 additions and 2 deletions
  1. 13
      utils/index.js

13
utils/index.js

@ -1,12 +1,15 @@
import env from '@/env/index.js' import env from '@/env/index.js'
import store from '@/store/index.js' import store from '@/store/index.js'
import { isDate } from './is.js'
import { isDate, isString } from './is.js'
/** /**
* 日期格式化样例 yyyy-mm-dd hh:MM:ss * 日期格式化样例 yyyy-mm-dd hh:MM:ss
* @param date Date 需要转换的日期 * @param date Date 需要转换的日期
* @param fmt string 转化的格式 yyyy-mm-dd hh:MM:ss * @param fmt string 转化的格式 yyyy-mm-dd hh:MM:ss
*/ */
export const dateTimeFormat = (date, fmt) => { export const dateTimeFormat = (date, fmt) => {
if (isString(date)) {
date = date.replace(/-/g, '/')
}
if (!isDate(date)) { if (!isDate(date)) {
date = new Date(date) date = new Date(date)
} }
@ -157,9 +160,15 @@ let _boundaryCheckingState = true
* @returns 时间差对象 * @returns 时间差对象
*/ */
export const difTime = (time, target) => { export const difTime = (time, target) => {
if (isString(time)) {
time = time.replace(/-/g, '/')
}
if (isString(target)) {
target = target.replace(/-/g, '/')
}
let begin = new Date(time).getTime() let begin = new Date(time).getTime()
// 兼容ios时间 // 兼容ios时间
let end = new Date(target.replace(/-/g, '/')).getTime()
let end = new Date(target).getTime()
let beyond = begin < end ? false : true let beyond = begin < end ? false : true
let diff = Math.abs(begin - end) let diff = Math.abs(begin - end)
// 计算天数 // 计算天数

Loading…
Cancel
Save