title: KnockoutJS dealing with bootstrap datepickers and date formats
body: <p>This is the datepicker binding i'm using (<em>im sorry but i forgot where i took it so i can't give the author proper credit. I will edit if i remember.</em>)</p>
  
  <pre><code>ko.bindingHandlers.datepicker = {
      init: function(element, valueAccessor, allBindingsAccessor) {
        //initialize datepicker with some optional options
        var options = allBindingsAccessor().datepickerOptions || {};
        $(element).datepicker(options);
  
        //when a user changes the date, update the view model
        ko.utils.registerEventHandler(element, "changeDate", function(event) {
               var value = valueAccessor();
               if (ko.isObservable(value)) {
                   value(event.date);
               }                
        });
      },
      update: function(element, valueAccessor)   {
          var widget = $(element).data("datepicker");
           //when the view model is updated, update the widget
          if (widget) {
              widget.date = ko.utils.unwrapObservable(valueAccessor());
              if (widget.date) {
                  widget.setValue();            
              }
          }
      }
  };
  
  function Model() {
    this.date = ko.observable();
  }
  
  function VM() {
    this.model = new Model();
    this.save = function(model) {
      $.post(someEndpoint, {model: model});
    }
  }
  
  &lt;input type='text' data-bind='datepicker: model().date, 
                                datepickerOptions: { format:"dd/mm/yyyy"}' /&gt;
  </code></pre>
  
  <p>This datepicker binding, and Bootstrap datepicker in general, deals with Date objects. So my observable will contain Dates.</p>
  
  <p>When i post data i see in console that it's posted with natural JS toString() format, which can vary according to your locale settings. For me, its</p>
  
  <pre><code>Mon Dec 02 2013 01:00:00 GMT+0100 (ora solare Europa occidentale)
  </code></pre>
  
  <p>When i receive this value server-side, i can't handle it because of this weird format.</p>
  
  <p>I could of course rewrite my model date attribute before posting, like so</p>
  
  <pre><code>  this.save = function(model) {
      model.date(model.date().format('YYYY-MM-DD'));
      $.post(someEndpoint, {model: model});
    }
  </code></pre>
  
  <p>but this is not a general purpose solution, furthermore when model.date is updated to string representation, datepicker triggers an error since it's expecting Date.</p>
  
  <p>How would you deal with this?</p>