var now = new Date();
let today = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate();//2018-3-27
var nowDayOfWeek = now.getDay();
console.log(nowDayOfWeek )
  1. 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();
},
 

js 时间处理函数 获取今天的前几天和后几天的任意一天的更多相关文章

  1. js时间格式化函数,支持Unix时间戳

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  2. MySQL内置函数获取几天前的日期

    如何采用mysql内置函数获取指定时间之前的日期呢? SELECT something FROM table_name WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY ...

  3. JS 时间格式化函数

    //时间格式化函数 Date.prototype.format = function (format) { var o = { "M+": this.getMonth() + 1, ...

  4. js时间比较,获取n天后(前)的日期

    <html> <head> <meta http-equiv="Content-Type" content="textml; charset ...

  5. JS数组at函数(获取最后一个元素的方法)介绍

    本文介绍js中数组的at函数,属于比较简单的知识普及性文章,难度不大. 0x00 首先,我们可以思考如下一个问题,如果要获取一个数组的最后一个元素(这是很常用的操作),我们应该怎么做? 相信大部分人能 ...

  6. JS 时间转换函数 字符串时间转换毫秒(互转)

    字符串转化为日期 let util = function(){ Date.prototype.Format = function(fmt) { var o = { "M+" : t ...

  7. js时间处理函数

    Date 对象的方法简介: ·Date    | 返回当日的日期和时间 ·getDate | 从 Date 对象返回一个月中的某一天 (1 ~ 31) ·getDay | 从 Date 对象返回一周中 ...

  8. JS时间处理,获取天时分秒

    //获取时间的天,小时,分钟,秒 function ToTime(second) { second = second / ; var result ; ) % ; ) % ; * )); ) { re ...

  9. js 时间日期函数小结

    Date.prototype.format = function(format){ var o = { "M+" : this.getMonth()+1, //month &quo ...

随机推荐

  1. 10-[协程] greenlet模块、 gevent模块

    1.greenlet模块:实现20个任务切换 如果我们在单个线程内有20个任务,要想实现在多个任务之间切换,使用greenlet模块可以非常简单地实现这20个任务直接的切换 使用yield生成器的方式 ...

  2. SpringCloud-容错处理Hystrix熔断器(五)

    前言:微服务架构应用的特点就是多服务,而服务层之间通过网络进行通信,从而支撑起整个应用系统,所以,各个微服务之间不可避免的存在耦合依赖关系.但任何的服务应用实例都不可能永远的健康或网络不可能永远的都相 ...

  3. loj2230 「BJOI2014」大融合

    LCT裸题 我LCT学傻了这题明显可以树剖我不会树剖了 本来的siz是Splay上的子树和,并没有什么用. 所以每个点维护虚子树和和子树和 虚子树和即虚边连接的子树和,且只有在access和link操 ...

  4. JetBrains激活 PyCharm | IntelliJ IDEA | CLion | WebStorm...

    最近,JetBrains的IDE火了起来,身为学Java的人,放弃了Eclipse,选择了Idea,还真有点不舍得呢... 虽然Idea不错(在我看来,比Eclipse好用),但是,人家是收费的呀.. ...

  5. 高可用OpenStack(Queen版)集群-3.高可用配置(pacemaker&haproxy)

    参考文档: Install-guide:https://docs.openstack.org/install-guide/ OpenStack High Availability Guide:http ...

  6. Cocos2d-x的跨平台原理

    为了充分发挥硬件性能,手机游戏通常使用Native App开发模式,这就造成开发商要为iOS 和Android平台用户开发不同的应用,无论是产品迭代还是运行维护都非常麻烦.Cocos2d-x在iOS, ...

  7. python3 通过qq邮箱定时发送邮件

    下面的代码为了每天定时发送监控邮件,监控什么呢?监控当天redis队列中是否有没有消费的数据,和当天mysql中新增的数据量 # -*- coding:utf-8 -*- from common.re ...

  8. Kubernetes探索学习003--关于Kubernetes的Pod

    关于Pod 关于Pod我们要慢慢去体会去接受它去使用它,尤其是运维人员这块需要从逻辑上形成认识,首先理解Pod是Kubernetes项目的原子调度单位.为什么是Pod而不是单个DockerContai ...

  9. iframe子页面position的fixed

    前言: 首先说一说我昨天天的苦逼经历.中午吃饭时一同事跟我说,他做的项目嵌套iframe后,子页面的position设置fixed失效了. 经过反复询问,得知他用了两层iframe,再加上最外的父页面 ...

  10. PLSQL Developer windows 64位连接数据库的问题

    使用PLSQL Developer 工具连接到数据库进行开发,目前主流windows 系统都是64位操作系统,而PLSQL Developer  只有32位程序,所以在连接数据库上遇到一些问题. PL ...