zoukankan      html  css  js  c++  java
  • js 时间处理函数 获取今天的前几天和后几天的任意一天

     
    var now = new Date();
    let today = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate();//2018-3-27
    var nowDayOfWeek = now.getDay();
    console.log(nowDayOfWeek )
    dateObject.getDay()
    返回值
    dateObject 所指的星期中的某一天,使用本地时间。返回值是 0(周日) 到 6(周六) 之间的一个整数。
     
     
    that.getWeek(0)   //今天
     
    //----------------------------------------------------------------------------------------------
    onLoad() {
    let _this = this;
    let spjlNo = this.data.spjlNo;
    let that = this;
    let user = wx.getStorageSync('user');
    promiseHandle(wx.getSystemInfo).then((data) => {
    _this.setData({
    updatePanelTop: data.windowHeight
    });
    });
    changeDate.call(this);
    let date = new Date();
    let todaytime = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
    this.setData({
    todaytime: todaytime,
    cheToday: todaytime,
    dayIndex:date.getDate()
    })

    // 服药记录
    that.sleepRq(todaytime);
    that.foodRq(todaytime);
    let now = new Date();
     
    let today = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate();
    let nowDayOfWeek = now.getDay();
    console.log(today)
    this.selectFn(nowDayOfWeek, today)
    },
    selectFn: function (n, toady) {
    let that=this;
    let weekdays = this.data.weekdays;
    if (n != 0) {
    weekdays[n - 1] = toady;
    } else {
    weekdays[weekdays.length - 1] = toady
    }
    // console.log(weekdays)
    // console.log(n)
    for (let i = 0; i < weekdays.length; i++) {
    if (weekdays[i] == '') {
    // console.log(i)
    if (i > n - 1) {
    weekdays[i] = this.getWeek(i - (n-1)+1 )
    } else {
    weekdays[i] = this.getWeek(i-(n-1)+1 )
    }
    }
    if (i >= weekdays.length - 1) {
    setTimeout(function () {
     
    that.chuLiday(weekdays);
    }, 300);

    }
    }
    },
    chuLiday: function (weekdays){
    let that=this;
    // var arr = str.split(",");
    for (let key in weekdays ){
    weekdays[key] = weekdays[key].split("-");
    }
    // console.log(weekdays)
    that.setData({
    weekdays: weekdays
    })

    },

    getWeek: function (i) {
    var now = new Date();

    var firstDay = new Date(now - (now.getDay() - 2) * 86400000);
    firstDay.setDate(firstDay.getDate() + i);
    let mon = Number(firstDay.getMonth()) + 1;
    return now.getFullYear() + "-" + mon + "-" + firstDay.getDate();
    },
     
  • 相关阅读:
    delete 用法总结
    js数组去重的常用方法总结
    学习中 常用到的string内置对象方法的总结
    Array 对象常用的方法总结
    javascript中运算符有哪些? 他们的优先级 呢?
    那些年前端经典面试题
    HHVM 3.0 发布,执行 PHP 的虚拟机
    【问底】徐汉彬:PHP7和HHVM的性能之争 (真是学到了很多)
    mysql 简单sql语句
    【问底】王帅:深入PHP内核(一)——弱类型变量原理探究
  • 原文地址:https://www.cnblogs.com/dianzan/p/8658080.html
Copyright © 2011-2022 走看看