6.4【微信小程序全栈开发课程】记录页面(四)--mpvue时间格式化

将数据库中的数据格式化成YYYY.MM.DD hh:mm的格式,比如2019.10.12 20:24

1、修改日期文件

mpvue框架中有一个专门格式化日期的文件src/utils/index.js文件,将日期格式化成“YYYY.MM.DD hh:mm”格式。

编辑src/utils/index.js文件,替换formatTime方法

export function formatTime (date) {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()

  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  const t1 = [year, month, day].map(formatNumber).join('.')
  const t2 = [hour, minute].map(formatNumber).join(':')

  return `${t1} ${t2}`
}
2、引入日期文件

编辑RecordList.vue文件,引入utils/index.js文件中的formatTime方法
并在data函数中添加create_time变量,使用formatTime方法格式化record记录中的时间

<script>
import {formatTime} from '../utils/index.js'
export default {
    props: ['record'],
    data () {
        return {
            create_time:formatTime(new Date(this.record.create_time)),
        }
    }
}
</script>

作者:猫宁一
全栈程序媛₍ᐢ •⌄• ᐢ₎一枚~ 热爱学习!热爱编程!
可关注【猫宁一】公众号领取我所有全栈项目代码哦~

点击查看课程目录:微信小程序全栈开发课程目录

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

喵宁一

点赞是最好的赞赏~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值