Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
66
rated 0 times [  69] [ 3]  / answers: 1 / hits: 51488  / 10 Years ago, sun, march 16, 2014, 12:00:00

My json response look like this:



[{Id:dab4580b-e24d-49f8-9fd5-2e968b10d3b5,Title:MVVM-Sidekick 入精,CreatedOn:/Date(1390272893353)/,IsChecked:false},{Id:66a0f134-e240-4cc4-96fa-ac3807853ca7,Title:Windows Phone 开发入精,CreatedOn:/Date(1390018447080)/,IsChecked:false}]


the CreatedOn date is in this kind of format: '/Date(1390272893353)/'



when I bind this result to html table, the date cannot be formatted:



<td>{{item.CreatedOn | date: 'yyyy-MM-dd HH:mm'}}</td>


still gives me:



/Date(1390272893353)/



I don't want to change any code on the server side (don't modify the json string), what's the best way to format this date?


More From » json

 Answers
10

One option is to write another filter and put it in the chain. E.g.:



app.filter(mydate, function() {
var re = //Date(([0-9]*))//;
return function(x) {
var m = x.match(re);
if( m ) return new Date(parseInt(m[1]));
else return null;
};
});


Basically it uses the regular expression to parse the string and make a Date (if the format is different than the one shown, you will have to tweak the regular expression).



Use it as:



<td>{{item.CreatedOn | mydate | date: 'yyyy-MM-dd HH:mm'}}</td>

[#71968] Friday, March 14, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
emiliotristinv

Total Points: 181
Total Questions: 99
Total Answers: 96

Location: Argentina
Member since Fri, Oct 21, 2022
2 Years ago
;