javascript - Angularjs Date format not constistant on browsers? -
i have following code:
app.filter('mydateformat',function mydateformat($filter){ return function(text){ var tempdate= new date(text.replace(/-/g,"/")); return $filter('date')(tempdate, "dd-mm-yyyy hh:mm:ss"); } });
which takes date database , puts correct format. here html:
<li ng-repeat="rows in latestqs | limitto:12"> <a href="#pubres/{{ rows._id }}"> {{ rows.title }} </a> <br> <small>by {{ rows.group_name }} @ {{ rows._createdat | mydateformat }}</small> </li>
this works fine on chrome, on ie9, displays as:
nan-nan-nan-0nan nan:nan:nan
where on chrome, its:
19-03-2014 14:00:19
any ideas how can round ?
use momentjs in filter, best date library out there...
app.filter('mydateformat',function mydateformat($filter){ return function(text){ var moment = moment(text); if(moment.isvalid) { var tempdate= new date(moment.value()); return $filter('date')(tempdate, "dd-mm-yyyy hh:mm:ss"); } } });
i have not tested code..but should work cross browser...
Comments
Post a Comment