微信小程序 时间戳距当前时间的长度

微信小程序 时间戳距当前时间的长度,第1张

注意:传入的dateTimeStamp时间戳以秒计时。如你想传以毫秒计时的值时先除1000

getDateDiff:function (dateTimeStamp) {

  var minute =  60

  var hour = minute * 60

  var day = hour * 24

  var halfamonth = day * 15

  var month = day * 30

  var now = Date.parse(new Date())/1000   //有些特殊 不能使用 new Date()

  var diffValue = now - dateTimeStamp

  if(diffValue <0){return}

  var monthC =diffValue/month

  var weekC =diffValue/(7*day)

  var dayC =diffValue/day

  var hourC =diffValue/hour

  var minC =diffValue/minute

  var result = ''

  if(monthC >段漏= 1){

      result="" + parseInt(monthC) + "月前"

  }

  else if(weekC>=1){

     世燃备 result="" + parseInt(weekC) + "周前"

  }

  else if(dayC>=1){

      result=""+ parseInt(dayC) +"天前"

  }

  else if(hourC>=1){

      result=""+ parseInt(hourC) +"小时前"

  }

  else if(minC>=1){

      result=""+ parseInt(minC) +"分钟前"

  }else{

     搜毁 result="刚刚"

  }

  return result

}//时间戳转化为几天前,几小时前,几分钟前

<van-calendar

      poppable="{{ false }}"

      show-confirm="{{ false }}"

      formatter="{{ formatter }}"

      class="calendar"

      show-title="{{ 伏世false }}"

      show-subtitle="{{ false }}"

    >

    </van-calendar>

onLoad(options){

    this.CalendarShow()

}

CalendarShow() {

    let _this=this

    var data = {}

    data.formatter = this.dayFormatter

      // 渲染日历

    this.setData({formatter: function (day) {

   缺拆肢     let month = day.date.getMonth() + 1

      御简  let date = day.date.getDate()

        for(let i of list){

          if(month ===i.month){

            if (date === i.day) {

              day.bottomInfo = '余票'+i.stock+'张'

            }

          }

        }

        return day

      } })

  },

一、使用来自不同页面函数

函数写在util.js页面

function formatTime(date) {

var year = date.getFullYear()

var month = date.getMonth() + 1

var day = date.getDate()

var hour = date.getHours()

var minute = date.getMinutes()

var second = date.getSeconds()

return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')

}

function formatNumber(n) {

n = n.toString()

return n[1] ? n : '0' + n

}

module.exports = {

formatTime: formatTime,

}

使用函数

图片描做唤述

图片描述

二、使用相同页面的函数

get_productInformation: function () {

。。。。

},

getZones:function(){

this.get_productInformation

},

三、使纯知凯用app.js内定义的函数

app.js代码

//app.js

App({

onLaunch: function() {

//调用API从本地缓存中获取数据

var logs = wx.getStorageSync('logs') || []

logs.unshift(Date.now())

wx.setStorageSync('logs', logs)

},

get_a_test:function(){

console.log('this is a test')

},

getUserInfo: function(cb) {

var that = this

if (this.globalData.userInfo) {

typeof cb == "function" &&cb(this.globalData.userInfo)

} else {

//调用登录接口

wx.getUserInfo({

withCredentials: false,

success: function(res) {

that.globalData.userInfo = res.userInfo

typeof cb == "function" &&cb(that.globalData.userInfo)

}

})

}

},

globalData: {

userInfo: null,

college_change:false

}

})

在其他页面中使用

图猛帆片描述


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12555570.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-26
下一篇 2023-05-26

发表评论

登录后才能评论

评论列表(0条)

保存