npm-dayjs-处理时间

726 阅读1分钟

dayjs-处理时间

文档地址

dayjs.fenxianglu.cn/category/di…

安装包

npm install dayjs --save

使用方式

<template>
    <div>        
    </div>
</template>

<script>
//必须引入: 引入包使用
const dayjs = require('dayjs') 
//其他引入: 有需要时引入
var weekYear = require('dayjs/plugin/weekYear')
var weekOfYear = require('dayjs/plugin/weekOfYear')
var isoWeeksInYear = require('dayjs/plugin/isoWeeksInYear')
var isLeapYear = require('dayjs/plugin/isLeapYear')
dayjs.extend(weekOfYear)
dayjs.extend(weekYear)
dayjs.extend(isoWeeksInYear)
dayjs.extend(isLeapYear)

export default {
    data () {
        return {

        }
    },
    methods: {

    },
    created () {
        // console.log(月初-----------------------')
        // console.log(dayjs().startOf('month').format('YYYY-MM-DD 00:00'))
        // console.log(月末-----------------------')
        // console.log(dayjs().endOf('month').format('YYYY-MM-DD 23:59'))
        // console.log(当前时间-----------------------')
        // console.log(dayjs().format('YYYY-MM-DD 23:59'))
        // console.log('上月月初-----------------------')
        // console.log(dayjs().startOf('month').subtract(1, 'month').format('YYYY-MM-DD 00:00'))
        // console.log('上月月末-----------------------')
        // console.log(dayjs().endOf('month').subtract(1, 'month').format('YYYY-MM-DD 23:59'))
        // console.log('获取月天数-----------------------')
        // console.log(dayjs().daysInMonth())
        // console.log('获取时间戳-----------------------')
        // console.log(dayjs('2019-01-25').valueOf()) //毫秒级 1548381600000
        // console.log(dayjs('2019-01-25').unix()) //秒级
        // console.log('获取当前第几周-----------------------')
        // console.log('第' + dayjs().week() + '周')
        // console.log('今年总共' + dayjs().isoWeeksInYear() + '周')
        // console.log('15天后-----------------------')
        // console.log(dayjs().add(15, 'day').format('YYYY-MM-DD'))
        // console.log('15天前-----------------------')
        // console.log(dayjs().add(-15, 'day').format('YYYY-MM-DD'))
        // console.log('是否闰年-----------------------')
        // console.log(dayjs().isLeapYear())
    },
}
</script>

<style lang="scss" scoped>
</style>