處理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