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. 12-[CSS]-margin塌陷,margin 0 auto,善用父级的padding

    1.margin塌陷 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  2. Windows Forms Application Creation and Initialization

    Windows Forms Application Creation and Initialization This topic details the steps performed after a ...

  3. krkr基础篇(一)

    krkr基础篇是我根据krkr的官方教程总结而来 推荐代替记事本的工具:editplus,点我下载 激活码:Vovan 3AG46-JJ48E-CEACC-8E6EW-ECUAW 一:创建新工程 1: ...

  4. Spring Boot之发送HTTP请求(RestTemplate详解)

    原文作者:微笑面对生活 https://www.javazhiyin.com/19714.html#comment-345 RestTemplate是Spring提供的用于访问Rest服务的客户端,R ...

  5. Netty源码分析第4章(pipeline)---->第2节: handler的添加

    Netty源码分析第四章: pipeline 第二节: Handler的添加 添加handler, 我们以用户代码为例进行剖析: .childHandler(new ChannelInitialize ...

  6. linux的date命令使用指定时间的加减方法与异常

    在一般网页里,date命令减时间方法为: date -d '-100 days' 我的需求是,在指定时间上减8小时.按一般理解来看,命令写成如下样子(有异常错误的写法): date -d " ...

  7. ceilometer 源码分析(polling)(O版)

    一.简单介绍ceilometer 这里长话短说, ceilometer是用来采集openstack下面各种资源的在某一时刻的资源值,比如云硬盘的大小等.下面是官网现在的架构图 这里除了ceilomet ...

  8. Hyperledger Fabric 中channel配置相关数据结构

    channel Configuration Transaction Hyperledger Fabric区块链网络中的配置存储在一个configuration-transaction的集合中,每个ch ...

  9. [leetcode-921-Minimum Add to Make Parentheses Valid]

    Given a string S of '(' and ')' parentheses, we add the minimum number of parentheses ( '(' or ')', ...

  10. No.110_第三次团队会议

    前端的易帜 前端在整个软件中有着举足轻重的地位.前端设计一般可以理解为视觉设计,前端开发则是前台代码的实现. 随着科技水平的提高和生产力的提高,人民对于审美的要求逐渐增高.在没有科技壁垒的情况下,是否 ...