如何正确显示日期yyyy-MM-dd hh:mm:ss与HTML5和Angularjs? [英] How can I show correctly Dates yyyy-MM-dd hh:mm:ss with HTML5 and Angularjs?
问题描述
我试图创建一个日期和时间的输入,但我没有办法做到这一点。
我尝试了输入 datetime ,
< tr>
< td> Date< / td>
< td>< input type =datetimename =fecha
placeholder =dd-MM-dd HH:mm:sssize =16
ng- model =data.action.date/>< / td>
< tt> value = {{data.action.date |日期:yyyy-MM-dd HH:mm:ss}}< / tt>
< / tr>
我得到这个
我也试过输入 datetime-local ,例如。
Moment.js是一个伟大的JavaScript库,用于格式化,转换和执行所有日期/时间相关任务 - 角度时刻只需在Angular中轻松暴露此库。
您可以直接在模板中使用amDateFormat过滤器,如下所示。
< span> {{message.time | amDateFormat:'dddd,MMMM Do YYYY,h:mm:ss a'}}< / span>
请参阅上述链接了解更多信息。
I'm trying to create an input with date and time but I don't get the way of doing it.
I've tried with input datetime,
<tr>
<td>Date</td>
<td><input type="datetime" name="fecha"
placeholder="dd-MM-dd HH:mm:ss" size="16"
ng-model="data.action.date" /></td>
<tt>value = {{data.action.date | date: "yyyy-MM-dd HH:mm:ss"}}</tt>
</tr>
and I get this
And I've tried as well input datetime-local like the example in angular doc
<tr>
<td>Date</td>
<td><input type="datetime-local" name="fecha"
placeholder="dd-MM-dd HH:mm:ss" size="16"
ng-model="data.action.date" /></td>
<tt>value = {{data.action.date | date: "yyyy-MM-dd HH:mm:ss"}}</tt>
</tr>
and I get this
How could I show the input with a date and time?
I recommend using the angular-moment directive for doing all date formatting in Angular: https://github.com/urish/angular-moment.
Moment.js is a great JavaScript library for formatting, converting and doing all date/time related tasks - angular-moment just exposes this library easily within Angular.
You can simply use the amDateFormat filter within your template as shown below.
<span>{{message.time | amDateFormat:'dddd, MMMM Do YYYY, h:mm:ss a'}}</span>
See the above link for more information.
这篇关于如何正确显示日期yyyy-MM-dd hh:mm:ss与HTML5和Angularjs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!