How do I properly display the date and time in AngularJS?
The output below shows both the input and the output, with and without the AngularJS date filter:
I know this is an old item, but thought I'd throw in another option to consider.
As the original string doesn't include the "T" demarker, the default implementation in Angular doesn't recognize it as a date. You can force it using new Date, but that is a bit of a pain on an array. Since you can pipe filters together, you might be able to use a filter to convert your input to a date and then apply the date: filter on the converted date. Create a new custom filter as follows:
app
.filter("asDate", function () {
return function (input) {
return new Date(input);
}
});
Then in your markup, you can pipe the filters together:
{{item.myDateTimeString | asDate | date:'shortDate'}}