为什么要是使用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