dip
dip

Reputation: 1261

Date filter is not working in my angular Controller

For my angular app , i want to format my date. But date filter in angular is not working. My code is as follows.

var newDate=$filter('date')(info.list.date, 'medium');

where info.list.date is "2014-06-25 07:22:47";

But for newDate I am not getting date in US-local format instead it is same as info.list.date.

Please let me know whats wrong in my code.

Upvotes: 0

Views: 585

Answers (1)

Anthony Chu
Anthony Chu

Reputation: 37520

The date filter requires the input to be a date, number, or a string conforming to ISO8601. Otherwise it just returns the original input (which is what you're seeing).

From the docs...

Date to format either as Date object, milliseconds (string or number) or various ISO 8601 datetime string formats (e.g. yyyy-MM-ddTHH:mm:ss.SSSZ and its shorter versions like yyyy-MM-ddTHH:mmZ, yyyy-MM-dd or yyyyMMddTHHmmssZ). If no timezone is specified in the string input, the time is considered to be in the local timezone.

In the above example, the string should be "2014-06-25T07:22:47".

Upvotes: 1

Related Questions