Knockout.js格式的日期项 [英] Knockout.js format date item

查看:106
本文介绍了Knockout.js格式的日期项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我看来,我希望显示一个包含日期的 knockout.js 绑定字段。它只是一个显示字段而不是输入字段。 basemodel.actionDate = ko.observable()

In my view I wish to display a knockout.js binded field that contains a date. It is just a display field and not an input field. Something like below when basemodel.actionDate = ko.observable()

<p class="display-field" data-bind="text: baseModel.actionDate"/> 

但是显示如下:

2013-06-17T11:56:18.4537687Z

什么是格式化 dd mm yyyy 的最简单方法。例如: 2013年6月17日

What is the easiest way to format this dd mm yyyy. eg: 17 June 2013?

推荐答案

我推荐 moment.js 日期格式化库。

使用它,你可以做某事像你这样看:

Using it, you can do something like this in your view:

<p class="display-field" data-bind="text: moment(baseModel.actionDate()).format('LL')"/>

这篇关于Knockout.js格式的日期项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆