日期组件实现以及调用

需求:日期默认展示一个月

js日期组件

// 获取当前日期
const today = function(){
    //获取当前日期
    let myDate = new Date();
    let nowY = myDate.getFullYear();
    let nowM = myDate.getMonth() + 1;
    let nowD = myDate.getDate();
    let endDate =
        nowY +
        "-" +
        (nowM < 10 ? "0" + nowM : nowM) +
        "-" +
        (nowD < 10 ? "0" + nowD : nowD); //当前日期
    return endDate;
}
// 获取三十天之前的日期
const datsago = function() {
    let lw = new Date(); //最后一个数字30可改,30天的意思
    lw.setTime(lw.getTime() + 3600 * 1000 * 24 * 30);
    let lastY = lw.getFullYear();
    let lastM = lw.getMonth() + 1;
    let lastD = lw.getDate();
    let startData =
        lastY +
        "-" +
        (lastM < 10 ? "0" + lastM : lastM) +
        "-" +
        (lastD < 10 ? "0" + lastD : lastD); //三十天之前日期
    return startData;
}
export{today,datsago}

vue页面调用以及使用

import {today,datsago} from "@/components/dayTime/index"

let startDate = today();
let endDate = datsago();
this.$set(this.queryParams, "param", [startDate, endDate]);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值