简体   繁体   English

我需要帮助来创建脚本以获取当前星期的日期

[英]I need help creating a script to pull the current dates for the week

I'm not very familiar with JavaScript but I want to create a script that will pull the every single day of the week for me. 我对JavaScript不太熟悉,但是我想创建一个脚本,它将对我来说是每周的每一天。 Here is what I am working with right now. 这就是我现在正在处理的内容。 在此处输入图片说明

I added the picture "Get date" and I would like to make it so that when I hit the "get date" button, it will go through the script and assign dates to the cells above Monday, Tuesday, Wednesday, etc. as 8/8, 8/9, 8/10. 我添加了图片“获取日期”,我想使其成为一个图片,以便当我单击“获取日期”按钮时,它将遍历脚本并将日期分配给星期一,星期二,星期三等上方的单元格,如8 / 8、8 / 9、8 / 10。

I think you'll have to do it in two steps: 我认为您必须分两个步骤进行操作:

  1. Find the last Monday (which is up to 6 days in the past) 查找最后一个星期一(过去最多6天)
  2. Starting from there, build a list of 7 days 从那里开始,建立7天清单

 var date = new Date(), daysOfWeek = []; // find last Monday while(date.getDay() != 1) { date.setDate(date.getDate() - 1); } // build array of dates for(var n = 0; n < 7; n++) { daysOfWeek.push((date.getMonth() + 1) + '/' + date.getDate()); date.setDate(date.getDate() + 1); } console.log(daysOfWeek); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM