title: Javascript Date issues returning 1 day less than set date - timezone
body: <p>Date formatting issues with Javscript Date().</p>
  
  <p>Background: I'm modifying Jquery UI datepicker and am having trouble with months and dates returning incorrect values.</p>
  
  <pre><code>$('#datefield').datepicker({
     beforeShowDay: function(date) {
        // issues experienced here - isolation test code below
        // Mon Aug 01 2016 00:00:00 GMT+1000 (AUS Eastern Standard Time)
        // DateMonth: 8 - ISO: 20160731
     }
  })
  </code></pre>
  
  <p>Based JS Date() construction on <a href="http://www.w3schools.com/jsref/jsref_obj_date.asp" rel="nofollow noreferrer">http://www.w3schools.com/jsref/jsref_obj_date.asp</a></p>
  
  <p>Sample code:</p>
  
  <pre><code>var d1 = new Date();
  var d1Month = d1.getMonth()+1;
  var d1ISO = d1.toISOString().slice(0,10).replace(/-/g,"");
  
  console.log(d1);
  console.log('1Month: '+d1Month+' ISO: '+d1ISO);
  
  var d2 = new Date(2016,06,31);
  var d2Month = d2.getMonth()+1;
  var d2ISO = d2.toISOString().slice(0,10).replace(/-/g,"");
  
  console.log(d2);
  console.log('2Month: '+d2Month+' ISO: '+d2ISO);
  
  var d3 = new Date('2016-07-31');
  var d3Month = d3.getMonth()+1;
  var d3ISO = d3.toISOString().slice(0,10).replace(/-/g,"");
  
  console.log(d3);
  console.log('3Month: '+d3Month+' ISO: '+d3ISO);
  
  var d4 = new Date(2016, 07, 01);
  var d4Month = d4.getMonth()+1;
  var d4ISO = d4.toISOString().slice(0,10).replace(/-/g,"");
  
  console.log(d4);
  console.log('4Month: '+d4Month+' ISO: '+d4ISO);
  </code></pre>
  
  <p>Output (console):</p>
  
  <pre><code>Wed Aug 24 2016 11:30:51 GMT+1000 (AUS Eastern Standard Time)
  1Month: 8 ISO: 20160824
  
  *Sun Jul 31 2016 00:00:00 GMT+1000 (AUS Eastern Standard Time)
  2Month: 7 ISO: 20160730
  
  Sun Jul 31 2016 10:00:00 GMT+1000 (AUS Eastern Standard Time)
  3Month: 7 ISO: 20160731
  
  *Mon Aug 01 2016 00:00:00 GMT+1000 (AUS Eastern Standard Time)
  4Month: 8 ISO: 20160731
  </code></pre>
  
  <p><strong>Why does 'd2' return 20160730 when the object returns 31st July?</strong></p>
  
  <p><strong>Why does 'd4' return 20160731 when the date set is 1st August?</strong></p>
  
  <p><strong>Why does d3 work correctly?</strong></p>
  
  <p>My Assumption is that that the ISO date somehow subtracts the GMT+10 and gets the previous day.</p>
  
  <p>I'm Aware of this step (protoype a function) to try and format <a href="https://stackoverflow.com/questions/3066586/get-string-in-yyyymmdd-format-from-js-date-object">Get String in YYYYMMDD format from JS date object?</a>
  but its still a mystery to me why the above produces different results...</p>
  
  <pre><code>return [this.getFullYear(), !mm[1] &amp;&amp; '0', mm, !dd[1] &amp;&amp; '0', dd].join('');
  </code></pre>