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();
},
 

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. 2_C语言中的数据类型 (九)逻辑运算符与if语句、switch、条件运算符?、goto语句与标号

    1          条件分支语句 1.1       关系运算符 在C语言中0代表false,非0代表真 1.1.1          < 小于 1.1.2          <= 小于 ...

  2. Docker部署MySQL容器

    从仓库下载镜像 sudo docker pull mysql:5.7   创建容器 docker run --name="mysql" \ -p 3306:3306 \ -v /U ...

  3. php从入门到放弃系列-01.php环境的搭建

    php从入门到放弃系列-01.php环境的搭建 一.为什么要学习php 1.php语言适用于中小型网站的快速开发: 2.并且有非常成熟的开源框架,例如yii,thinkphp等: 3.几乎全部的CMS ...

  4. 如何解决zabbix snmp异常超时、不稳定、时通时断:Timeout

    针对平时工作中,zabbix snmp出现异常超时.不稳定.时通时断:Timeout while connecting 等的情况,以下我将以使用乐维监控为例,进行解决方案的详细叙述.   一.问题:设 ...

  5. 基础的 sparkSQL操作

    spark连接mysql操作 数据库jdbc 连接封装 package test.com import org.apache.spark.sql.{DataFrame, SparkSession} / ...

  6. sqli-labs学习笔记 DAY6

    DAY 6 sqli-labs lesson 30 与上一题一样,需要用到HPP 查看源代码,参数两边加上了双引号,直接使用lesson 26a与lesson 27a的脚本即可 sqli-labs l ...

  7. Algorithm - 贪心算法使用场景 ( LEETCODE —— Best Time to Buy and Sell Stock II)

    先看一道leetcode题: Best Time to Buy and Sell Stock II Say you have an array for which the ith element is ...

  8. 工作小应用:EXCEL查找两列重复数据

    工作案例:excel存在A列.B列,需要找出B列没有A列的数据,具体做法如下(以office2007做案例): 1.点击 公式-定义名称 ,选中A列,填写名称“AAA”,选中B列,填写名称“BBB”: ...

  9. python2.7 倒计时

    From: http://www.vitostack.com/2016/06/05/python-clock/#more Python公告 Python 发布了一个网站 http://pythoncl ...

  10. RN 离线包集成后需要注意的一些问题

    1.ReactNative 开发中如何去掉iOS状态栏的"Loading from..." 等淡黑色的弹框,很难看? 在 AppDelegate.h 中引入: #import &l ...