【发布时间】:2018-07-03 01:02:25
【问题描述】:
您好,我正在尝试将此日历的起始工作日从周日更改为周一。
但我不明白var k = ... 行中发生了什么。这行代码试图用人类语言表达什么?
https://codepen.io/xmark/pen/WQaXdv?editors=1010
// June 2018
var k = lastDay_of_LastMonth - firstDay_of_Month+1;
27
//_____________________________________________________________________
// TEST
var lastDay_of_LastMonth = new Date(2018, 5, 0); // May 31st 2018
document.write('Today is: ' + lastDay_of_LastMonth.toLocaleString());
// Today is: 5/31/2018, 12:00:00 AM
var firstDay_of_Month = new Date(2018, 5, 1); // June 1st 2018
firstDay_of_Month."getDay()";
5
// June 2018
var k = lastDay_of_LastMonth - firstDay_of_Month+1;
lastDay_of_LastMonth.setDate(lastDay_of_LastMonth.getDate() - 6);
document.write('<br>X days ago was: ' + lastDay_of_LastMonth.toLocaleString());
// X days ago was: 5/25/2018, 12:00:00 AM
//_____________________________________________________________________
// June 2018
27 = 31 - 5+1;
我从这个线程中看到,这段代码正在计算(日期 - 天数),倒数天数。但我无法理解它用人类语言对日历代码做了什么。 31-(5+1) = 25 的数学不应该意味着它会回到过去 6 天,为什么我会得到 27 的值?
Subtract days from a date in JavaScript
【问题讨论】:
-
我修复了一些他们混淆的东西。
-
如果您将代码作为可运行的 sn-p 在这里发布会更好,但请先查看 How to create a minimal, complete and verifiable example。 ;-)
-
我用我新编辑的代码文件更新了以前的线程。 *.com/questions/51014363/…
标签: javascript date calendar