js 时间格式化 兼容safari 苹果手机

export function formatTime (fmt, date) {
  date = new Date(date + '+08:00') // 兼容safari
  var o = {
    'M+': date.getMonth() + 1,
    'd+': date.getDate(),
    'h+': date.getHours(),
    'm+': date.getMinutes(),
    's+': date.getSeconds(),
    'q+': Math.floor((date.getMonth() + 3) / 3),
    'S': date.getMilliseconds()
  }
  if (/(y+)/.test(fmt)) {
    fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
  }
  for (var k in o) {
    if (new RegExp('(' + k + ')').test(fmt)) {
      fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
    }
  }
  return fmt
}
export default {
  formatTime
}
let start = formatTime('yyyy-mm-dd hh:mm', '2019-05-01T09:00:00') // 2019-05-01 09:00 兼容了safari
 
new Date('2019-05-01T09:06:08') 改为new Date('2019-05-01T09:06:08+08:00') 就同时兼容浏览器

 

 

 

https://blog.csdn.net/qq_34849240/article/details/80736624

https://www.cnblogs.com/laosunlaiye/p/9395327.html

 

posted @ 2019-04-21 17:55  James2019  阅读(3098)  评论(0编辑  收藏  举报