title: Userscript to autofill jQuery UI Datepicker - wrong date format
body: <p>I'm trying to autofill a <a href="https://api.jqueryui.com/datepicker/" rel="nofollow">jQuery UI datepicker</a>, but the date is being pasted in <code>MM/DD/YYYY</code> format. I need it to be pasted in <code>yy-mm-dd</code> format. When the native datepicker functionality is used, the date is filled correctly. I'm attempting to set the date using the following methods, but each fills in the wrong format. How can I properly set the date in <code>yy-mm-dd</code> format instead of the default <code>MM/DD/YYYY</code> format?</p>
  
  <p>The page uses jQuery 2.1.4 and jQuery UI 1.11.4.</p>
  
  <pre><code>// initialize date
  var cur = new Date();
  
  // methods I've tried
  $('.selector').datepicker('setDate', cur);
  
  $('.selector').datepicker('formatDate', 'yy-mm-dd');
  $('.selector').datepicker('setDate', cur);
  
  $('.selector').datepicker('option', 'formatDate', 'yy-mm-dd');
  $('.selector').datepicker('setDate', cur);
  
  $('.selector').datepicker('option', 'formatDate', 'yy-mm-dd');
  $('.selector').datepicker('refresh');
  $('.selector').datepicker('setDate', cur);
  
  // from answers below
  $('.selector').datepicker({dateFormat: 'yy-mm-dd'});
  $('.selector').datepicker('setDate', cur);
  
  // this method changes the format displayed in the field, but the form's
  // validation throws an error that it is in the wrong format. focus/unfocus
  // on the field manually after this sets the date back to the previous format.
  $('.selector').datepicker('setDate', cur);
  var s = cur.getFullYear() + '-' + (('0' + (cur.getMonth() + 1)).slice(-2)) +
          '-' + (('0' + (cur.getDate())).slice(-2));
  </code></pre>