添加这个javascript:
String.prototype.Format = function (fmt) {
var myDate = this;
var o = {
"M+": myDate.getMonth() + 1,
"d+": myDate.getDate(),
"h+": myDate.getHours(),
"m+": myDate.getMinutes(),
"s+": myDate.getSeconds(),
"q+": Math.floor((myDate.getMonth() + 3) / 3),
"S": myDate.getMilliseconds()
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (myDate.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
};
然后你可以像这样使用:
<span data-bind="text: createDate().Format('MM/DD/YYYY')"></span>