My dates come out of the database looking like this: 2013-11-21 17:43:20
I\'m trying to user Angular\'s date filter to turn them into something prettier
You need to convert your date string to something supported by Angular, like ISO 8601 format. You could convert it like this:
$scope.Object.created = new Date($scope.Object.created).toISOString();
Live demo here (click).
To do this on the fly, you need a custom filter. Live demo here (click).
Markup:
{{Object.created | dateToISO | date:'shortDate'}}
JavaScript:
app.filter('dateToISO', function() {
return function(input) {
return new Date(input).toISOString();
};
});
Here's a simple way to convert your date manually (firefox):
app.filter('badDateToISO', function() {
return function(badTime) {
var goodTime = badTime.replace(/(.+) (.+)/, "$1T$2Z");
return goodTime;
};
});