vue 獲取當時時間轉換成時間戳比較


var payTimeEnd = new Date( 傳:年月日 ).getTime() //獲取到的是 毫秒級別的

 var newData = Date.parse(new Date()); // 獲取當前時間,也是 毫秒級別的

  

// 或者做一個騷操作,通過正則去除  - 和 : 來比較

function compareTime(startTime,endTime) {  
    var start_time = startTime.replace(/-|\s|:|\//g,''); 
    var end_time = endTime.replace(/-|\s|:|\//g,'');  
    if (start_time < end_time) { return true; }
    else { return false; } 
 },

  

// 年月日轉換為時間戳

new Date(2022+'-'+2+'-'+21+' '+11+':'+55+':'+33).getTime() / 1000

 

//獲取當前時間 年月日時分秒

var endTime = ''

        var myDate = new Date();
        //獲取當前年
        var year = myDate.getFullYear();
        //獲取當前月
        var month = myDate.getMonth() + 1;
        //獲取當前日
        var date = myDate.getDate();
        var h = myDate.getHours();       //獲取當前小時數(0-23)
        var m = myDate.getMinutes();     //獲取當前分鍾數(0-59)
        var s = myDate.getSeconds();
        endTime = year + this.p(month) + this.p(date) + this.p(h) +this.p(m) + this.p(s)

 

p(s) {
      return s < 10 ? '0' + s : s;
    },

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM