uniapp 获取时间选择,今天,明天,后天

选择今天,明天或者后天中的某一天

外面的样子
在这里插入图片描述

选取时候的样子
在这里插入图片描述
image是右侧的箭头

<view class="addText">
    <picker class="pickClass" :range="visitorTime" :value="visitorTimeIndex" @change="visitorChange">
	    <view class="innerBox">
		    <view>{{visitorTime[visitorTimeIndex]}}</view>
		    <image src="/static/homeImgs/vTangle.png" mode="widthFix" class="arrDown"></image>
	    </view>
    </picker>
 </view>

data的代码

data(){
	return{
		visitorTime:[],//访客时间
		visitorTimeNum:[],//访客时间另一种格式,接口传参需要
		visitorTimeIndex:0,//当前访客所选时间
	}
},

methods的代码

//获取时间
getCurrentTime(){			
	var time = new Date()
	var tempTime= [];
	var yM = time.getFullYear() + '年' + (this.checkTime(time.getMonth()+1)) +'月'
	var today = time.getDate()
	var moni1 = time.setDate(today + 1);
	var yM2 = new Date(moni1).getFullYear() + '年' + (this.checkTime(new Date(moni1).getMonth() + 1)) +'月'

	var time1 = new Date()
	var today2 = time1.getDate()
	var moni2 = time1.setDate(today2 + 2);
	var yM3 = new Date(moni2).getFullYear() + '年' + (this.checkTime(new Date(moni2).getMonth() + 1)) +'月'
	var temp1 = yM + this.checkTime(today) +'日' +'  今天'
	var temp2 = yM2 + this.checkTime(new Date(moni1).getDate()) +'日' +'  明天'
	var temp3 = yM3 + this.checkTime(new Date(moni2).getDate()) +'日' +'  后天'
	tempTime.splice(0,0,temp1)
	tempTime.splice(1,0,temp2)
	tempTime.splice(2,0,temp3)
	this.visitorTime = tempTime;
	
	var tempNum = [];
	var yNum =  time.getFullYear() + '-' + (this.checkTime(time.getMonth()+1)) +'-';
	var yNum1 =  new Date(moni1).getFullYear() + '-' + (this.checkTime(new Date(moni1).getMonth()+1)) +'-';
	var yNum2 =  new Date(moni2).getFullYear() + '-' + (this.checkTime(new Date(moni2).getMonth()+1)) +'-';
	var num1 = yNum + this.checkTime(today)
	var num2 = yNum1 + this.checkTime(new Date(moni1).getDate())
	var num3 = yNum2 + this.checkTime(new Date(moni2).getDate())
	tempNum.splice(0,0,num1)
	tempNum.splice(1,0,num2)
	tempNum.splice(2,0,num3)
	this.visitorTimeNum = tempNum;
	
},
checkTime(i){
    if(i<10) return "0"+i;
    return i;
},
//选择通行时间
visitorChange(e){
	this.visitorTimeIndex = e.detail.value;
},

css样式

/* 选择时间 */
.addText{
  width: 84%;
  box-sizing: border-box;
  padding-right: 18rpx;
}
.pickClass{
  width: 100%;
}
.innerBox{
  width: 100%;
  display: flex;
  justify-content: space-between;
  flex-wrap: nowrap;
  font-size: 32rpx;
}
.arrDown{
  width: 40rpx;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值