(1)创建一个处理时间格式的js,内容如下:

../../utils/formatDate.js

export function formatDate(date, fmt) {
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
}
let o = {
'M+': date.getMonth() + 1,
'd+': date.getDate(),
'h+': date.getHours(),
'm+': date.getMinutes(),
's+': date.getSeconds()
}
for (let k in o) {
if (new RegExp(`(${k})`).test(fmt)) {
let str = o[k] + ''
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str))
}
}
return fmt
} function padLeftZero(str) {
return ('00' + str).substr(str.length)
}

(2)在vue文件中需要格式化时间戳的地方,使用filters过滤器,做如下处理:

<template>
<div class="date">{{item.pass_time | formatDate}}</div>
</template>

<script type="text/ecmascript-6">
 // 引入formatDate.js 文件
import {formatDate} from '../../utils/formatDate.js'
export default {
filters: {
    
    //方法一: yyyy-MM-dd hh:mm
formatDate(time) {
time = time * 1000
let date = new Date(time)
console.log(new Date(time))
return formatDate(date, 'yyyy-MM-dd hh:mm')
}     
     //方法二: yyyy-MM-dd
formatDate(time) {
// time = time * 1000
let date = new Date(time)
console.log(new Date(time))
return formatDate(date, 'yyyy-MM-dd')
}
} }

</script>

  补充:time应为格式为13位unix时间戳,如果拿到的时间戳是10位的unix时间戳,因此需要乘以1000。

转载地址: https://blog.csdn.net/qq_32678401/article/details/81983364

vue 将时间戳转换成日期格式 (一)的更多相关文章

  1. js angular 时间戳转换成日期格式 年月日 yyyy-MM-dd

    昨天写项目,要把时间戳转换成日期格式发给后端 我就去网上找 看到的一些都不是我想要的 索性自己就写了一个如图 下面是angular 模式 $scope.getMyDate = function(str ...

  2. js将时间戳转换成日期格式-陈远波

    var timestamp =1539598555000;//时间戳 //时间戳转换成time格式function timestampToTime(timestamp) { var date = ne ...

  3. jqgrid 时间戳转换成日期格式

    原文 :http://blog.csdn.net/caoyuancsdn/article/details/52984524 Java script  接收到的时间参数是时间戳*1000 functio ...

  4. javaScript中将时间戳转换成日期格式

    function DateFormt(time, format) { ); var o = { , "d+": testDate.getDate(), "h+" ...

  5. js时间戳转成日期格式

    将时间戳转换成日期格式:// 简单的一句代码var date = new Date(时间戳); //获取一个时间对象 注意:如果是uinx时间戳记得乘于1000.比如php函数time()获得的时间戳 ...

  6. javascript时间戳转换成指定格式的日期

    //时间戳转换成指定格式的日期DateTool.IntDatetimeTo = function(time, format){    var testDate = new Date(time);    ...

  7. moment使用,把某个时间时间戳转换成日期

    1.某个时间时间戳转换成日期 moment(时间戳 ).format("YYYYMMDD")   2.获取某个日期当月的最后一天 moment(“2019-04-05”).endO ...

  8. CTime,Systemtime的比较还有转换成日期格式。

    vc为我们提供了两种日期型的变量. 一种是CTime.他的缺点就是年份只支持到2038年,以后的日期就不支持啦,如果你的项目有20-30年的寿命,你就选择使用SYSTEMTIME.这个时间函数来进行比 ...

  9. vue filters 时间戳转化成时间格式

    vue filters 时间戳转化成时间格式 filters: { formatDate: function (time) { var re = /-?\d+/ var m = re.exec(tim ...

随机推荐

  1. 实战二:LoadRunner创建一个测试脚本

    问题一:执行脚本浏览器不能自动启动??? 原因:loadrunner11只支持IE9以下浏览器和火狐低版本浏览器 解决办法:1.IE浏览器取消勾选[启用第三方浏览器扩展]启动IE,从[工具]进入[In ...

  2. 004-行为型-03-观察者模式(Observer)

    一.概述 当对象间存在一对多关系时,则使用观察者模式(Observer Pattern).比如,当一个对象被修改时,则会自动通知它的依赖对象. 定义了对象之间的一对多依赖,让多个观察者对象同时监听某一 ...

  3. matlab学习笔记2--matlab的帮助

    一起来学matlab-matlab学习笔记2--matlab的帮助 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考书籍 <matlab 程序设计与综合应用>张德丰等著 感谢张 ...

  4. Spring Cloud Hystrix Dashboard的使用 5.1.3

      Hystrix除了可以对不可用的服务进行断路隔离外,还能够对服务进行实时监控.Hystrix可以实时.累加地记录所有关于HystrixCommand的执行信息,包括每秒执行多少.请求成功多少.失败 ...

  5. 无法嵌入互操作类型"NationalInstruments.TestStand.Interop.UI.ExecutionViewOptions"。请改用适用的接口

    参考一下文章说明, 修改Interop.UI动态库的引入属性为 False,不再报错:   VS2010,VS2012,VS2013中,无法嵌入互操作类型“……”,请改用适用的接口的解决方法 在VS2 ...

  6. LeetCode_299. Bulls and Cows

    299. Bulls and Cows Easy You are playing the following Bulls and Cows game with your friend: You wri ...

  7. NETTY 心跳机制

    最近工作比较忙,但闲暇之余还是看了阿里的冯家春(fengjiachun)的github上的开源代码Jupiter,写的RPC框架让我感叹人外有人,废话不多说,下面的代码全部截取自Jupiter,写了一 ...

  8. ubuntu14.0.4安装kafka

    1. 下载 zookeeper-3.4.12 zookeeper download 2 配置Zookeeper 进入 zookeeper 的 conf 目录下,找到 zoo_sample.cfg 文件 ...

  9. [ kvm ] 嵌套虚拟化

    1. 前言 在学习 kvm 的过程中,需要在虚拟机中再次开启虚拟机,这里就需要使用到嵌套虚拟化,做个记录吧. 2. 配置嵌套虚拟化 2.1 查看物理机是否支持嵌套虚拟化 cat /sys/module ...

  10. 【Leetcode_easy】844. Backspace String Compare

    problem 844. Backspace String Compare solution1: class Solution { public: bool backspaceCompare(stri ...