javascript - how to get Monday as first day in jquery datepicker -


if run code snippet, you'll see monday day number 7, how can monday first day of week example: monday 05/01/2017 week no. 1 tuesday 05/02/2017 week no. 2

<html lang="en">  <head>    <meta charset="utf-8">    <meta name="viewport" content="width=device-width, initial-scale=1">      <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>  <script type="text/javascript" src="/scripts/jquery.ui.datepicker-it.js"></script>    <script>  $(function() {    var weekstart = new date(2017, 1, 27);    var roster = ['work', 'off', 'off', 'work', 'work', 'work', 'work',    	'off', 'work', 'work', 'work', 'off', 'off', 'work'];    $('#date').datepicker({mindate: weekstart, onselect: function(datestr) {      var date = $(this).datepicker('getdate');      var days = math.floor((date.gettime() - weekstart.gettime()) / (24 * 60 * 60 * 1000));      var week = math.floor(days / 7) % 2;      $('#week').val(week + 1);      $('#day').val($.datepicker.formatdate('dd', date));      $('#work').val(roster[week * 7 + date.getday() - 1]);    }});  });  </script>  </head>  <body>     <p>date: <input type="text" id="date"></p>  <p>day: <input type="text" id="day"></p>  <p>week: <input type="text" id="week"></p>  <p>work: <input type="text" id="work"></p>    </body>  </html>

you missing firstday: 1 param.

<html lang="en">  <head>    <meta charset="utf-8">    <meta name="viewport" content="width=device-width, initial-scale=1">      <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>  <script type="text/javascript" src="/scripts/jquery.ui.datepicker-it.js"></script>    <script>  $(function() {    var weekstart = new date(2017, 1, 27);    var roster = ['work', 'off', 'off', 'work', 'work', 'work', 'work',    	'off', 'work', 'work', 'work', 'off', 'off', 'work'];    $('#date').datepicker({ firstday: 1,  mindate: weekstart, onselect: function(datestr) {      var date = $(this).datepicker('getdate');      var days = math.floor((date.gettime() - weekstart.gettime()) / (24 * 60 * 60 * 1000));      var week = math.floor(days / 7) % 2;      $('#week').val(week + 1);      $('#day').val($.datepicker.formatdate('dd', date));      $('#work').val(roster[week * 7 + date.getday() - 1]);    }});  });  </script>  </head>  <body>     <p>date: <input type="text" id="date"></p>  <p>day: <input type="text" id="day"></p>  <p>week: <input type="text" id="week"></p>  <p>work: <input type="text" id="work"></p>    </body>  </html>


Comments