27726

Setting up the fist day of the week. Calendar. JS

Question:

I used <a href="http://jszen.blogspot.ru/2007/03/how-to-build-simple-calendar-with.html" rel="nofollow">this script</a> 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.

Answer1:

Here is a working code for week starting from Monday: <a href="http://jsfiddle.net/VL44m/" rel="nofollow">http://jsfiddle.net/VL44m/</a>

Two changes were made:

From cal_days_labels = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];<br /> 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++) {

Answer2:

Here an enhancement of the Nikhil Talreja's code: <a href="http://codepen.io/jacknumber/pen/RWLyQW" rel="nofollow">http://codepen.io/jacknumber/pen/RWLyQW</a>

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

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

Recommend

  • LINQ to Entities does not recognize the method
  • PHP create range of dates
  • Full calendar business hour constrain on day click event
  • Drupal: create a node with employee working hours
  • function cannot execute on segment because it accesses relation
  • AngularJs ng-repeat filtering by a deeper tier of data
  • Is it possible to disable certain weekdays in DatePickerDialog?
  • Get or convert Week of year to ISO week
  • MySql - get days remaining
  • Returning this from a constructor function in JS
  • pandas computation in each group
  • Excel VBA How to populate a multi-dimensional (3d) array with values from multiple excel ranges?
  • What is the use of a session store?
  • How to get the date of next specified day of week
  • C# - Most efficient way to iterate through multiple arrays/list
  • netsh acl setting (need alternative method - registry settings?)
  • Primefaces ManyCheckbox inside ui:repeat calls setter method only for last loop
  • Remove final comma from string in vb.net
  • Abort upload large uploads after reading headers
  • Record samples being played with OpenAL
  • Retrieving value from sql ExecuteScalar()
  • java.lang.NoClassDefFoundError: com.parse.Parse$Configuration$Builder on below Lollipop versions
  • Different response to non-authenticated users and AJAX calls
  • What is Eclipse's Declaration View used for?
  • C# - Serializing and deserializing static member
  • How to recover from a Spring Social ExpiredAuthorizationException
  • How to convert from System.Drawing.Color to Excel.ColorFormat in C#? Change comment color
  • Incrementing object id automatically JS constructor (static method and variable)
  • ILMerge & Keep Assembly Name
  • Large data - storage and query
  • Do create extension work in single-user mode in postgres?
  • Properly structure and highlight a GtkPopoverMenu using PyGObject
  • WOWZA + RTMP + HTML5 Playback?
  • R: gsub and capture
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • Comma separated Values
  • Matrix multiplication with MKL
  • python regex in pyparsing
  • how does django model after text[] in postgresql [duplicate]
  • How to load view controller without button in storyboard?