AngularJS - 小数点后无法删除数字

时间:2021-07-22 16:50:50

Im pulling in a JSON value from and API call that is returning this date and time value:

我从和返回此日期和时间值的API调用中提取JSON值:

2016-07-25 10:50:14.000

Im trying to remove the last 3 zeros but don't know how to do this.

我试图删除最后3个零但不知道如何做到这一点。

I have tried:

我努力了:

<div class="createdOn">Created On: {{ details['Created At'] | number:2 }} </div>

But that displays nothing at all. Is there a way for me to use jQuery to grab that text and then remove the zeros at the end?

但这根本不显示任何东西。有没有办法让我使用jQuery抓取该文本,然后删除最后的零?

Thanks for any help.

谢谢你的帮助。

2 个解决方案

#1


2  

Your date is in fact a string. So in angular that should work :

您的日期实际上是一个字符串。所以在角度应该工作:

 <div class="createdOn">Created On: {{ details['Created At'] | limitTo:19 }}</div>

For ref : https://docs.angularjs.org/api/ng/filter/limitTo

对于ref:https://docs.angularjs.org/api/ng/filter/limitTo

Like str point it, you can too treat it like a date (your format permit it and it's perhaps a better solution):

就像str指出它一样,你也可以把它当成日期(你的格式允许它,它可能是一个更好的解决方案):

{{ details['Created At'] | date:'yyyy-MM-dd HH:mm:ss' }}

Reference: https://docs.angularjs.org/api/ng/filter/date

参考:https://docs.angularjs.org/api/ng/filter/date

#2


0  

Another solution is http://momentjs.com/ you can assign your formats easily.

另一个解决方案是http://momentjs.com/,您可以轻松分配您的格式。

#1


2  

Your date is in fact a string. So in angular that should work :

您的日期实际上是一个字符串。所以在角度应该工作:

 <div class="createdOn">Created On: {{ details['Created At'] | limitTo:19 }}</div>

For ref : https://docs.angularjs.org/api/ng/filter/limitTo

对于ref:https://docs.angularjs.org/api/ng/filter/limitTo

Like str point it, you can too treat it like a date (your format permit it and it's perhaps a better solution):

就像str指出它一样,你也可以把它当成日期(你的格式允许它,它可能是一个更好的解决方案):

{{ details['Created At'] | date:'yyyy-MM-dd HH:mm:ss' }}

Reference: https://docs.angularjs.org/api/ng/filter/date

参考:https://docs.angularjs.org/api/ng/filter/date

#2


0  

Another solution is http://momentjs.com/ you can assign your formats easily.

另一个解决方案是http://momentjs.com/,您可以轻松分配您的格式。