Young87

SmartCat's Blog

So happy to code my life!

游戏开发交流QQ群号60398951

当前位置:首页 >跨站数据测试

vue 日期格式化-将时间2020-11-10T12:01:50.942转换成2020-11-10 12:01

返回数据:

页面效果:

 代码如下:

dateFormat ('Tue Mar 06 2012 00:00:00 GMT+0800', 'yyyy-MM-dd');//示例
function dateFormat (time, format) {
  var t = new Date(time)
  var tf = function (i) {
    return (i < 10 ? '0' : '') + i
  }
  return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function (a) {
    switch (a) {
      case 'yyyy':
        return tf(t.getFullYear())
      // break
      case 'MM':
        return tf(t.getMonth() + 1)
      // break
      case 'mm':
        return tf(t.getMinutes())
      // break
      case 'dd':
        return tf(t.getDate())
      // break
      case 'HH':
        return tf(t.getHours())
      // break
      case 'ss':
        return tf(t.getSeconds())
      // break
    }
  })
}

 

除特别声明,本站所有文章均为原创,如需转载请以超级链接形式注明出处:SmartCat's Blog

上一篇: 我下单了这些AI智能硬件!发现...

下一篇: ​百度能源AI中台筑基企业智能升级,推进智慧能源系统新发展

精华推荐