美文网首页
2020-05-13时间的转换(时空换换换)

2020-05-13时间的转换(时空换换换)

作者: 夏天的风2020 | 来源:发表于2020-05-13 14:09 被阅读0次
    //1.时间的转换
    
        timeDefault() {
          //let date = new Date()
          let now = new Date()
          let Y = now.getFullYear()
          let M = now.getMonth() + 1
          let D = now.getDate()
          let h = now.getHours()
          let m = now.getMinutes()
          M < 10 ? M = "0" + M : M = M
          D < 10 ? D = "0" + D : D = D
          h < 10 ? h = "0" + h : h = h
          m < 10 ? m = "0" + m : m = m
          //let s1 = `${Y}-${M}-${D} ${h}:${m}:00`
          let s1 = `${Y}-${M}-${D}`
          return s1
        },
    
     // 计算当前日期的前七天
        timeDefault(){
          let now = new Date()
          let Q7 = new Date(now.getTime() - 3600 * 1000 * 24 * 7)
    
          let Y = now.getFullYear()
          let M = now.getMonth() + 1
          let D = now.getDate()
          M < 10 ? M = '0' + M : M = M
          D < 10 ? D = '0' + D : D = D
    
          let qY = Q7.getFullYear()
          let qM = Q7.getMonth() + 1
          let qD = Q7.getDate()
          qM < 10 ? qM = '0' + qM :qM = qM
          qD < 10 ? qD = '0' + qD : qD = qD
    
          let s1 = `${Y}-${M}-${D}`
          let s2 = `${qY}-${qM}-${qD}`
          
          console.log("当前日期打印")
          console.log(s1)
          //this.form.date = [s2,s1]
          this.form.begin_date = s1
          this.form.end_time = s2
          //return s1
        },
    
    //获取当月的每个周一
       //参数d为某个日期的时间对象
      //参数m为月份
        getMondays(d,m){
          //let d = new Date()
          let month = d.getMonth()
          let mondays = []
          d.setDate(1) //设置当前月的第一天 ,返回的是毫秒数
          //获取本月的第一个星期一
          while(d.getDay() !== 1){
            console.log('进入while---d.getDay()')
            d.setDate(d.getDate() + 1)
          }
          //获取月中所有其他星期一
          while(d.getMonth() + 1 == Number(m)){
            console.log('d.getMonth() == Number(m)')
            mondays.push(d.getDate())
            d.setDate(d.getDate() + 7)
          }
          console.log("mondays获取到了么")
          console.log(mondays)
          return mondays
        },
    
    // 时间戳转化成标准时间格式
    getTime (time) {
          let now = new Date(time)
          let y = now.getFullYear()
          let m = now.getMonth() + 1
          m = m < 10 ? '0' + m : m
          let d = now.getDate()
          d = d < 10 ? '0' + d : d
          let hh = now.getHours()
          hh = hh < 10 ? '0' + hh : hh
          let mm = now.getMinutes()
          mm = mm < 10 ? '0' + mm : mm
          let ss = now.getSeconds()
          ss = ss < 10 ? '0' + ss : ss
          return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
        },
    
    //当前时间是否在某个时间段之间
    isnoticeTime (sTime, eTime) {
          if (!sTime || !eTime) return true
          let now = new Date().getTime()
          let sDate = new Date(sTime.replace(/-/g, '/'))
          let eDate = new Date(eTime.replace(/-/g, '/'))
          if (eDate.getTime() < now || sDate.getTime() > now) {
            return true
          } else {
            return false
          }
        },
    
    //判断某时间是否距离当前时间半小时内
        compareTime (val) {
          if (!val) return false
          let now = new Date().getTime()
          if ((val + 30 * 60 * 1000) < now) {
            return false
          } else {
            return true
          }
        },
    

    相关文章

      网友评论

          本文标题:2020-05-13时间的转换(时空换换换)

          本文链接:https://www.haomeiwen.com/subject/oyennhtx.html