JSFiddle - React, Tailwind, and code Playground
HTML
<input data-bind="value : rawDate" type="date">
<hr>
<span data-bind="html: log" />
JavaScript
var currentDate = (new Date()).toISOString().split('T')[0];
var viewModel = {
rawDate : ko.observable(currentDate),
log : ko.observable(""),
logDate : function () {
this.log(this.log() + this.MyDate() + " : " +
typeof(this.MyDate()) + "<br>");
}
};
viewModel.MyDate = ko.computed(function () {
var val = this.rawDate();
if (typeof val === 'string') val = new Date(val);
return val;
}, viewModel)
viewModel.MyDate.subscribe(function (date) {
viewModel.logDate();
});
ko.applyBindings(viewModel);
viewModel.logDate()