A filter that I commonly use takes an ISO date & converts it to MS. Then you can use whatever date
filter you want from angular
example date:
"2014-04-01 10:16:00"
Filter
.filter('isoToMS', function() {
return function(input) {
var ms = Date.parse(input.replace(/-/g,"/"));
return ms;
};
})
HTML
{{result.date | isoToMS | date:'dd/MM/yyyy HH:mm'}}
The regex /-/g,"/"
within the .replace()
is to handle inconsistencies with browsers. Chrome will convert to ms properly with -
in the ISO date. But FF will not. They require /
. So by replacing all -
with /
, it works across browsers.
Another Dev on my team prefers a different filter:
.filter('dateToISO', function() {
return function(input) {
input = new Date(input).toISOString();
return input;
};
})
I haven't tested this one though. I haven't always had great luck using ISO dates with Angular filters (hence why I take an ISO date & convert it to MS in my first solution).