agon024 agon024 - 3 months ago 7
Javascript Question

AngularJS - Can't remove numbers after decimal pont

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

2016-07-25 10:50:14.000


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

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?

Thanks for any help.

Answer

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

Like str point it, You can to treat it like a date (your format permit it):

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

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