2021-06-08——根据系统时间段判断,当前在哪个时间段

根据系统时间段判断,当前在哪个时间段

一号20-八号20点

八号20-十五号20点

十五号20-二十二20点

二十二号20-次月一号20
export function formatDateUtil() {

        // 获取当前日期
        var date = new Date();
        var myweekday = date.getDate()
        console.log("时间",date.toLocaleDateString())

        const months =date.getFullYear()+"-"+(date.getMonth()+1)
        let week: any = '';
        var Hours = date.getHours(); //获取当前月份(0-11,0代表1月)
        var Ye= date.getFullYear()+1
        var Year= date.getFullYear()
       
        var Month = date.getMonth() + 2; 
        var Monthss = date.getMonth() + 1; 
 
      //用=号判断
      if(Monthss==12&&myweekday >= 22){
          if(Hours>20){
            week = Year+"-"+Monthss  + '/22——' + Ye+"-"+1 + '/1'
            return week 
          }else{
            week = Year+"-"+12  + '/15——' + Year+"-"+12 + '/22'
            return week 
          };

      }else if(Monthss==1&&myweekday == 1){

        if (Hours < 20) {
            week = Year-1+"-"+12  + '/22——' + Ye+"-" + '/1'
            return week ;
          } else {
            week = Year+"-"+Monthss + '/1——' + Year+"-"+Monthss + '/8'
            return week;
          }
      } else{
          if(myweekday==1){
            if (Hours < 20) {
                week = months + '/22——' + Year+"-"+Month + '/1'
                return week ;
              } else {
                week = months + '/1——' + months + '/8'
                return week;
              }
          }
    if (myweekday == 22) {
      if (Hours > 20) {
        week = months + '/22——' + Year+"-"+Month+ '/1'
        return week;
      } else {
        week = months + '/15——' + months + '/22'
        return week;
      }
    }
    if (myweekday == 15) {
      if (Hours > 20) {
        week = months + '/15——' + (months) + '/22'
        return week;
      } else {
        week = months + '/8——' + months + '/15'
        return week;
      }
    }
    if (myweekday == 8) {
      if (Hours > 20) {
        week = months + '/8——' + months + '/15'
        return week;
      } else {
        week = months + '/1——' + months + '/8'
        return week;
      }
    }
    if (myweekday > 15 && myweekday < 22) {
      week = months + '/15——' + (months) + '/22'
      return week;
    }
    if (myweekday > 8 && myweekday < 15) {
      week = months + '/8——' + (months) + '/15'
      return week;
    }

    if (myweekday > 1 && myweekday < 8) {
      week = months + '/1——' + (months) + '/8'
      return week;
    }
    if (myweekday > 22) {
      week = months + '/22——' + Year+"-"+Month + '/1'
      return week;
    }
}
  }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值