获取当前时间 (年月日选择框 - 当天 -七天 - 一个月 - 三个月)

获取当前时间 (年月日选择框)

效果图在这里插入图片描述
代码

 <el-date-picker  size="small"  v-model="date"  type="daterange"  range-separator="至" unlink-panels :picker-options="pickerOptions" start-placeholder="开始日期"  end-placeholder="结束日期"></el-date-picker>
data(){
	//搜索条件
	date:  [],      // 时间年月日
     pickerOptions: {
	      shortcuts: [{
	          text: '当天',
	          onClick(picker) {
	            const end = new Date();
	            const start = new Date();
	            picker.$emit('pick', [start, end]);
	          }
	        }, {
	          text: '七天',
	          onClick(picker) {
	            const end = new Date();
	            const start = new Date();
	            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
	            picker.$emit('pick', [start, end]);
	          }
	        }, {
	          text: '一个月',
	          onClick(picker) {
	            const end = new Date();
	            const start = new Date();
	            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
	            picker.$emit('pick', [start, end]);
	          }
	        }, {
	          text: '三个月',
	          onClick(picker) {
	            const end = new Date();
	            const start = new Date();
	            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
	            picker.$emit('pick', [start, end]);
	          }
	        }]
	      },
}
  created(){
 // 当前年月日
          var now = new Date();
          var year = now.getFullYear(); //得到当前年份
          var month = now.getMonth()+1; //默认得到月份是上一个月,如果当前是3月,这个值为2月
          var endOfDate = new Date(year, month, 0).getDate(); // 获取本月最后一天
          month = month.toString().padStart(2, "0");	//当小于10时,显示为01.02.03
          this.startdate = `${year}-${month}-01`;//拼接日期
          this.enddate = `${year}-${month}-${endOfDate}`;
          this.date[0]=this.startdate;
          this.date[1]=this.enddate;
  }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值