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

js 时间格式化 兼容safari 苹果手机的更多相关文章

  1. js 时间格式化 (兼容safari)

    js 时间格式化,兼容IE8和safari浏览器. function formatDate(date, fmt, near, type) { var dateStr = date; if (!date ...

  2. js时间格式化函数,支持Unix时间戳

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  3. 时间戳显示为多少分钟前,多少天前的JS处理,JS时间格式化,时间戳的转换

    var dateDiff = function (timestamp) { // 补全为13位 var arrTimestamp = (timestamp + '').split(''); for ( ...

  4. 表单序列化json字符串和js时间格式化

    js时间格式化 new Date().format("时间格式") Date.prototype.format = function(fmt) { var o = {        ...

  5. js时间格式化函数(兼容IOS)

    * 时间格式化 * @param {Object} dateObj 时间对象 * @param {String} fmt 格式化字符串 */ dateFormat(dateObj, fmt) { le ...

  6. js时间格式化

    const formatDate = timestamp => { const date = new Date(timestamp); const m = date.getMonth() + 1 ...

  7. js时间格式化(yy年MM月dd日 hh:mm)

    //时间格式化 Date.prototype.format = function (format) { var o = { "M+": this.getMonth() + 1, / ...

  8. js 时间格式化 -- 时间加减实现

    时间格式化的方法: Date.prototype.Format = function (fmt) { //author: meizz var o = { "M+": this.ge ...

  9. JS 时间格式化函数

    //时间格式化函数 Date.prototype.format = function (format) { var o = { "M+": this.getMonth() + 1, ...

随机推荐

  1. Linux如何查找文件的创建时间

    Linux的文件能否找到文件的创建时间取决于文件系统类型,在ext4之前的早期文件系统中(ext.ext2.ext3),文件的元数据不会记录文件的创建时间,它只会记录访问时间.修改时间.更改时间(状态 ...

  2. 国产多维数据库 NeuralCube!中国人自己的大数据底层核心技术!

    商业转载请联系作者获得授权,非商业转载请注明出处. 提到‘数据库’,首先被想到的肯定是Oracle.DB2.SQL Server.MySql这些传统的关系型数据库.数据库的概念是非常宽泛的,除了上述的 ...

  3. servlet之转发与重定向的区别

    转发(服务器端跳转):  一次请求 <jsp:forward> request.getRequestDispatcher("new.jsp").forward(requ ...

  4. uboot的启动过程-FDT

    uboot的启动过程,省略了汇编部分之后,第一个执行函数是board_init_f(),在uboot/common目录的board_f.c中   board_init_f函数,首先初始化了全局数据 # ...

  5. js坚持不懈之18:trim()方法

    trim()方法,类似Python中的strip(),用去去除字符串对象前后的空格. <!DOCTYPE html> <html> <body> <scrip ...

  6. jQuery标签插件tagsinput.js

    官网地址: http://xoxco.com/projects/code/tagsinput/ github地址: https://github.com/xoxco/jQuery-Tags-Input ...

  7. java的环境变量配置失败(java.exe、javaw.exe、javaws.exe优先级问题冲突)

    前言:首先安装了intelliJ Idea 其次安装了JDK 1.8 配置完三个系统变量后,java和javac执行不通过 配置过程 1.我的电脑(右键)--->属性---->高级---& ...

  8. nextInt()和nextLine()一起使用时的注意点

    问题原因:nextLine()会把nextInt(),next(),nextDouble(),nextFloat()的结束换行符作为字符串读入,进而不需要从键盘输入字符串nextLine便已经转向了下 ...

  9. jdk自带的监测cpu/内存、线程等信息的工具

    Jvisualvm:jdk自带的监控工具(JDK1.6+) 在终端中输入Jvisualvm回车出现如下界面:

  10. 为Spring Cloud Ribbon配置请求重试(Camden.SR2+)

    当我们使用Spring Cloud Ribbon实现客户端负载均衡的时候,通常都会利用@LoadBalanced来让RestTemplate具备客户端负载功能,从而实现面向服务名的接口访问. 下面的例 ...