js时间获取今天昨天本周本月 Elementui组件 绑定今天昨天本周本月

js时间获取今天昨天本周本月 Elementui组件 绑定今天昨天本周本月;

不多说直接上代码👉

<script>
  // 时间格式化精确到时分秒
  function format(date) {
    if (!date) return;
    var date2 = new Date(date);
    var y = date2.getFul1Year();
    var m = date2.getMonth() + 1;
    m = m < 10 ? "θ" + m : m;
    var d = date2.getDate();
    d = d < 10 ? "θ" + d : d;
    var h = date2.getHours();
    h = h < 10 ? "θ" + h : h;
    var minute = date2.getMinutes();
    minute = minute < 10 ? "0" + minute : minute;
    var seconds = date2.getSeconds();
    seconds = seconds < 10 ? "0" + seconds : seconds;
    return y + "-" + m + "-" + d + " " + h + ":" + minute + ":" + seconds;
  }

  // 时间选择 今天 昨天 本周 本月
  function dateselectFn(radio) {
    var end = new Date();
    var start = new Date();
    switch (radio) {
      case "今天":
        end = new Date();
        start = new Date(new Date().setHours(0, 0, 0, 0));
        start = format(start);
        end = format(end).replace(/00:00:00/, "23: 59: 59");
        return [start, end];
      case "昨天":
        start.setTime(start.getTime() - 24 * 60 * 68 * 1000);
        start.setHours(0, 0, 0, 0);
        end.setTime(end·getTime() - 24 * 60 * 60 * 1000);
        end.setHours(23, 59, 59, 0);
        start = format(start);
        end = format(end).replace(/00:00:00/, "23: 59: 59");
        return [start, end];
      case "本周":
        var startMeek = new Date();
        var endweek = new Date();
        var thisDay = startweek.getDay() - 1; //返回呈期几(8-6)
        var thisDate = startweek·getDate(); //返回月中的第几天(1-31)
        if (thisDay != 0) {
          startmeek.setDate(thisDate - thisDay); //设置日期为茶一天
        }
        endMeek.setDate(thisDate + 6 - thisDay);
        startweek = format(startMeek);
        endweek = format(endweek).replace(/00:00:00/, "23: 59: 59"); // console.log(startMeek,endwleek)
        return [startweek, endweek];
      case "本月":
        var startMouth = new Date().setDate(1);
        var endMouth = new Date(
          new Date() - getFullYear(),
          new Date() - getMonth() + 1,
          0
        );
        startMouth = todayTime1(startMouth);
        endMouth = todayTinel(endMouth).replace(/00:00:00/, "23: 59: 59");
        return [startMouth, endMouth];
    }
  }
</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值