处理elementui日期选择器获取的时间


 <el-date-picker
                  v-model="value1"
                  type="daterange"
                  size="small"
                  range-separator="to"
                  @change="getSTime"
                  format="yyyy-MM-dd"
                  start-placeholder="Start date"
                  end-placeholder="End date">
                </el-date-picker>

vue  中的组件代码

组建获取到的是///

Thu May 12 2016 08:00:00 GMT+0800 (中国标准时间)这种格式的

利用change时间处理只到天的

getSTime(val){
          this.value1=val
         console.log(this.value1[0])
         var d = new Date(this.value1[0]);
         var youWant=d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate();
         console.log(youWant)
         var d2 = new Date(this.value1[1]);
         var youWant2=d2.getFullYear() + '-' + (d2.getMonth() + 1) + '-' + d2.getDate();
         console.log(youWant2)
         this.queryInfo.startDate=youWant
         this.queryInfo.endDate=youWant2
         //
         // console.log(youWant.trim().split(" ")[0])
         // console.log(youWant2.trim().split(" ")[0])


       },

得到的类似//2020-5-5-------------------2020-6-6

到时间的话

youWant=d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds();

需要的话做补0处理就行了


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM