0
{{ map.thedate }}

The above outputs 2014-06-29 16:43:48

When I try the below code it still shows the same date as above.

{{ map.thedate | date:'medium' }}

2 Answers 2

1

your date is not in ISO format. Use a filter to convert your input to a date and then apply the date filter

app.filter("toDate", function () {
    return function (input) {
        return new Date(input);
    }
});

Then in html markup:

{{map.thedate | toDate | date:'medium'}}
Sign up to request clarification or add additional context in comments.

Comments

1

Conver your date, here is an example:

for (var i=0; i<map.length; i++) {
    var unixTime = (new Date(map[i].thedate)).getTime();         
    map[i].thedate= unixTime;        
}        

AngularJS will not accept that format of date, this is an easy solution to iterate over your dataset and convert it to a format it will accept.

Another alternative is to do the same thing about on the server-side. Just iterate over it and convert it to a unix timestamp.

This is a description from the docs. on what it will accept:

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.