js實現時間大小比較


前端對接接口數據時,有時候后台返回兩個時間,需要做比較處理狀態。

1、后台返回兩個時間,前端做處理:

 // 獲取熱門活動
    getHotActLimit () {
      var that = this,
        myDate = Date.parse(new Date()),
        begin,
        end
      wx.request({
        url: conf.HOST + "/whg-wechat/index.action?method=getHotActLimit",
        data: {},
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success (res) {
          that.hotList = res.data[0].list
          for (var i = 0; i < that.hotList.length; i++) {
            begin = new Date(that.hotList[i].ACT_TIME_BEGIN).getTime()
            end = new Date(that.hotList[i].ACT_TIME_END).getTime()
            if (begin > myDate) {
              that.hotList[i].ACT_STAGE = '未開始'
            } else if (end < myDate) {
              that.hotList[i].ACT_STAGE = '已結束'
            } else if (begin < myDate < end) {
              that.hotList[i].ACT_STAGE = '進行中'
            }
          }
        }
      })
    } 

 

根據時間的比較,來判斷活動的狀態:

 

2、后台返回一個活動報名時間,前端處理與當前時間做比較,判斷報名時間是否已經截止:

function getShykList(id) {
  var data = { actId: id }
  var actDetail = HOST + '/stddj-geteway/api/act/actDetail'
  ajax_all(true, 'GET', actDetail, data, function(res) {
    var endtime = new Date(res.info.actTime).getTime()
    var nowtime = new Date().getTime()
    // 活動時間小於當前時間,不能報名
    if (endtime < nowtime && res.info.checkApply != 1) {
      res.info.overdue = true
    }
}

  

 


免責聲明!

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



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