Browse Source

ios 时间戳bug

devlop
mo-bai 4 years ago
parent
commit
17ac3542ff
2 changed files with 15 additions and 2 deletions
  1. 13
      utils/index.js
  2. 4
      utils/is.js

13
utils/index.js

@ -1,12 +1,15 @@
import env from '@/env/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
* @param date Date 需要转换的日期
* @param fmt string 转化的格式 yyyy-mm-dd hh:MM:ss
*/
export const dateTimeFormat = (date, fmt) => {
if (isString(date)) {
date = date.replace(/-/g, '/')
}
if (!isDate(date)) {
date = new Date(date)
}
@ -127,9 +130,15 @@ export function round(number, precision) {
* @returns 时间差对象
*/
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()
// 兼容ios时间
let end = new Date(target.replace(/-/g, '/')).getTime()
let end = new Date(target).getTime()
let beyond = begin < end ? false : true
let diff = Math.abs(begin - end)
// 计算天数

4
utils/is.js

@ -19,3 +19,7 @@ export function isArray(val) {
export function isDate(val) {
return is(val, 'Date')
}
export function isString(val) {
return is(val, 'String')
}
Loading…
Cancel
Save