正确地格式化为AngularJS ASP.NET MVC日期 [英] Correctly format ASP.NET MVC dates for AngularJS
问题描述
我用AngularJS从ASP.NET服务器应用程序获取数据,并在客户端显示出来。下面是我收到:
专案编号│CreatedOn
══════════╪══════════════════════
13241│/日期(1338364250000)/
13411│/日期(1338370907000)/
正如你所看到的,是不正确显示的日期。我想格式化日期 YYYY-MM-DD HH:MM:SS
。我怎样才能做到这一点?
HTML视图:
< DIV NG-NG应用程序控制器=FirstCtrl>
<表>
<&THEAD GT;
&所述; TR>
&所述; TD>
专案编号
< / TD>
&所述; TD>
创建于
< / TD>
< / TR>
< / THEAD>
<&TBODY GT;
< TR NG重复=队队中的阶级=缩略图>
&所述; TD>
{{team.ProjectID}}
< / TD>
&所述; TD>
{{team.CreatedOn}}
< / TD>
< / TR>
< / TBODY>
< /表>
< / DIV>
操作方法:
公共JsonResult的getUser()
{
返回JSON(新{数据= ProjectService.Get prefixUsedCount(1).ToArray()});
}
JSON结果返回:
{数据:[{专案编号:13241,CreatedOn:\\ /日期(1338364250000)\\ /},
{专案编号:13411,CreatedOn:\\ /日期(1338370907000)\\ /}]
如果改变MVC格式是不是一种选择,你可以做像这样:
{{team.CreatedOn.slice(6,-2)|日期:'YYYY-MM-DD HH:MM:SS'}}
键位是 .slice(6,-2)
,它剪掉所有的垃圾字符,让你只在毫秒时代的时间。
I am using AngularJS to get data from an ASP.NET server application and display it on the client side. Here is what I'm getting:
ProjectID │ CreatedOn
══════════╪══════════════════════
13241 │ /Date(1338364250000)/
13411 │ /Date(1338370907000)/
As you can see, the date is not being displayed correctly. I want to format the date as YYYY-MM-DD HH:MM:SS
. How can I do this?
The HTML view:
<div ng-app ng-controller="FirstCtrl">
<table>
<thead>
<tr>
<td>
ProjectID
</td>
<td>
CreatedOn
</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="team in teams" class="thumbnail">
<td>
{{team.ProjectID}}
</td>
<td>
{{team.CreatedOn}}
</td>
</tr>
</tbody>
</table>
</div>
The action method:
public JsonResult GetUser()
{
return Json(new { data = ProjectService.GetPrefixUsedCount(1).ToArray() });
}
The JSON result returned:
{"data":[{"ProjectID":13241,"CreatedOn":"\/Date(1338364250000)\/"},
{"ProjectID":13411,"CreatedOn":"\/Date(1338370907000)\/"}]
If changing the format in MVC isn't an option, you can do it like so:
{{ team.CreatedOn.slice(6, -2) | date: 'yyyy-MM-dd HH:mm:ss' }}
The key bit is .slice(6, -2)
, which trims off all the junk characters and leaves you with just the epoch time in milliseconds.
这篇关于正确地格式化为AngularJS ASP.NET MVC日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!