博客
关于我
Vue中使用moment格式化时间
阅读量:381 次
发布时间:2019-03-05

本文共 938 字,大约阅读时间需要 3 分钟。

前言

JS插件moment模块可以格式化时间。

安装

cnpm install moment --save

在main.js中引入:

import moment from 'moment';Vue.prototype.$moment = moment;

使用

//模块中使用:{   {   this.$moment(item.endTime).format("YYYY-MM-DD HH:mm:ss")}}//默认格式化当前时间的两种方式:this.$moment().format('YYYY-MM-DD HH:mm:ss')    this.$moment(Date.now()).format('YYYY-MM-DD HH:mm:ss')//今天是星期几:this.$moment().format('d');//昨天this.$moment(Date.now() - 24 * 60 * 60 * 1000)//转化成Date对象this.$moment().toDate()// 早于this.$moment('2010-10-20').isBefore('2010-10-21') // truethis.$moment('2010-10-20').isBefore('2010-12-31', 'year') // falsethis.$moment('2010-10-20').isBefore('2011-01-01', 'year') // true//是否相等:isSame 晚于:isAfter// 是否在时间范围内this.$moment('2010-10-20').isBetween('2010-10-19', '2010-10-25') // truethis.$moment('2010-10-20').isBetween('2010-01-01', '2012-01-01', 'year') // falsethis.$moment('2010-10-20').isBetween('2009-12-31', '2012-01-01', 'year') // true//是否是闰年this.$moment().isLeapYear()

转载地址:http://ttmg.baihongyu.com/

你可能感兴趣的文章
Netty源码—2.Reactor线程模型一
查看>>
Netty源码—2.Reactor线程模型二
查看>>
Netty源码—3.Reactor线程模型三
查看>>
Netty源码—3.Reactor线程模型四
查看>>
Netty源码—4.客户端接入流程一
查看>>
Netty源码—4.客户端接入流程二
查看>>
Netty源码—5.Pipeline和Handler一
查看>>
Netty源码—5.Pipeline和Handler二
查看>>
Netty源码—6.ByteBuf原理一
查看>>
Netty源码—6.ByteBuf原理二
查看>>
Netty源码—7.ByteBuf原理三
查看>>
Netty源码—7.ByteBuf原理四
查看>>
Netty源码—8.编解码原理一
查看>>
Netty源码—8.编解码原理二
查看>>
Netty源码解读
查看>>
netty的HelloWorld演示
查看>>
Netty的Socket编程详解-搭建服务端与客户端并进行数据传输
查看>>
Netty的网络框架差点让我一夜秃头,哭了
查看>>
Netty相关
查看>>
Netty简介
查看>>