在小程序中使用dayjs

为什么要是使用dayjs  :

        a.小程序  在ios 和 android有兼容性问题 ,使用dayjs可以不用考虑兼容性
        b.使用dayjs真的真的 超级方便 可以少写很多代码

        比如:

//没有使用 dayjs

formatDateTime: date => {
    if(!date){
      return '';
    }
    date = new Date(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()

    return [year, month, day].map(utils.formatNumber).join('/') + ' ' + [hour, minute, second].map(utils.formatNumber).join(':')
  },


//使用dayjs

import dayjs from './dayjs.min.js'

formatDateTime: date => {
   return dayjs(date).format('YYYY/MM/DD HH:mm:ss')
},

使用dayjs:

1.下载dayjs   npm install dayjs --save  在下载后找到dayjs.min.js (下方附带了dayjs.min.js)  将dayjs.min.js 添加到项目中

2.在需要使用dayjs的单元中引用    import dayjs from './dayjs.min.js'  注意路劲

3.使用    dayjs(date).format('YYYY/MM/DD HH:mm:ss')

下面是dayjs.min.js  直接复制就好了

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.dayjs=e()}(this,function(){"use strict";var t="millisecond",e="second",n="minute",r="hour",i="day",s="week",u="month",a="quarter",o="year",h=/^(\d{4})-?(\d{1,2})?-?(\d{0,2})[^0-9]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?.?(\d{1,3})?$/,f=/\[([^\]]+)]|Y{2,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,c=function(t,e,n){var r=String(t);return!r||r.length>=e?t:""+Array(e+1-r.length).join(n)+t},d={s:c,z:function(t){var e=-t.utcOffset(),n=Math
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值