最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Setting up the fist day of the week. Calendar. JS - Stack Overflow

programmeradmin0浏览0评论

I used this script to create a calendar with JavaScript. I rewrote it enough, for instance, I built viewing of the previous and next month's days, viewing previous or next month, etc. But the basic algorithm remains the same as it was written in that article (for loops "// fill in the days").

Well now, when everything works pretty good, I need the first day of the week to be Monday, not Sunday. Unfortunately, I can't imagine how to change the loops in order this feature to work.

So, how do I need to change the loops to make Monday the first day of the week? Thanks.

I used this script to create a calendar with JavaScript. I rewrote it enough, for instance, I built viewing of the previous and next month's days, viewing previous or next month, etc. But the basic algorithm remains the same as it was written in that article (for loops "// fill in the days").

Well now, when everything works pretty good, I need the first day of the week to be Monday, not Sunday. Unfortunately, I can't imagine how to change the loops in order this feature to work.

So, how do I need to change the loops to make Monday the first day of the week? Thanks.

Share Improve this question asked Jul 8, 2014 at 5:28 Th.GlebTh.Gleb 251 silver badge4 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Here an enhancement of the Nikhil Talreja's code: http://codepen.io/jacknumber/pen/RWLyQW

To fix month started by Sunday and avoid list of month length, use this:

var startingDay = firstDay.getDay() == 0 ? 7 : firstDay.getDay();

Here is a working code for week starting from Monday: http://jsfiddle/VL44m/

Two changes were made:

From cal_days_labels = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
To cal_days_labels = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat','Sun'];

From

// this loop is for weekdays (cells)
    for (var j = 0; j <= 6; j++) { 

To

// this loop is for weekdays (cells)
    for (var j = 1; j <= 7; j++) {
发布评论

评论列表(0)

  1. 暂无评论