I have a models.DateTimeField() field in my django model.
I am using backbone to display this model. I want to be able to pretty print the date.
I tried the following but it says invalid date:
App.House = Backbone.Model.extend({
url: function() {
return API_URL + this.id;
},
initialize: function() {
// displays Invalid Date when printed in template
this.set('pretty_created_at',new Date(this.get('created_at')));
},
});
When looking at the API response from the server, I see that the date has the following format:
"created_at": "2012-06-24T05:00:00+00:00"
After debugging I realized that what was happening is that the model was being initalized like this:
Therefore, the
created_atattribute was undefined.I decided to use
timeago.jsto display the information. However, a workaround for this problem could be: