"bootstrap compatable calendar" 周一不开始

"bootstrap compatable calendar" not starting on monday

我正在尝试让此代码为我工作:

https://codepen.io/bbarry/pen/Eopdk

我希望日历从星期一开始。我已经将 days:[] 从 Sa-So 更改为 .js.

中的 Mo-Su

但这只会改变 header。日期还是错了,12月1日还是星期三,不过今年应该是星期二

我很确定问题出在 .html:

中这部分附近的某个地方
 <thead>
  <tr class="c-weeks">
    {{ for (i = 0; i < 7; i++) { }}
      <th class="c-name">
        {{: days[i] }}
      </th>
    {{ } }}
  </tr>
</thead>
<tbody>
  {{ for (j = 0; j < 6 && (j < 1 || mode === 'month'); j++) { }}
  <tr>
    {{ for (i = 0; i < 7; i++) { }}
    {{ if (thedate > last) { dayclass = nextmonthcss; } else if (thedate >= first) { dayclass = thismonthcss; } }}
    <td class="calendar-day {{: dayclass }} {{: thedate.toDateCssClass() }} {{: date.toDateCssClass() === thedate.toDateCssClass() ? 'selected':'' }} {{: daycss[i] }} js-cal-option" data-date="{{: thedate.toISOString() }}">
      <div class="date">{{: thedate.getDate() }}</div>
      {{ thedate.setDate(thedate.getDate() + 1);}}
    </td>
    {{ } }}
  </tr>
  {{ } }}
</tbody>

我已经尝试更改循环 (i = 0; i < 7; i++) 但我无法修复它。

html 文件中的循环 for (i = 0; i < 7; i++) 仅打印 7 header 个单元格,迭代数组 days 并在单元格中打印数组值。如您所见,这不会影响日期。您需要处理日期 object.

您在 html 文件中有 2 个日期 object:一个用于月视图,另一个用于周视图和日视图。

月视图

日期 object 在 html 文件的第 12 行实例化:

first = new Date(year, month, 1), 

这意味着新日期 object,传递参数年(以上为当前年份)和月份(以上定义为当前年份)。第三个参数是一个月中的哪一天被视为该月的第一天。设置此参数 0.

first = new Date(year, month, 0), 

周视图

日期 object 在 html 文件的第 20 行实例化:

thedate = new Date(date);

日期设置在第 21 行:

thedate.setDate(date.getDate() - date.getDay());

日期设置如下:

thedate.setDate(date.getDate() - date.getDay()+1);

日视图: 无需更改,因为您使用相同的object周视图。

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date