0

Long story short, I'm trying to display a date that came from json.

This is what I tried:

{{ item.CreateDate | date }}
{{ item.CreateDate | date : 'MM/dd/yyyy' }}

This is what I get: /Date(1413010800000)/

I want to get 10/14/2014

What am I doing wrong? Thanks

Z .
  • 12,657
  • 1
  • 31
  • 56
  • What do you get if you don't use the date filter? I'm wondering if your variable is not a date object. – Brocco Nov 28 '14 at 19:19
  • if no filter I get the same... the json looks like this: `CreateDate: "/Date(1413010800000)/"` – Z . Nov 28 '14 at 19:25
  • Looks like you have `Date(1413010800000)` as a string see here: http://plnkr.co/edit/QRvSPekGhxBTXPtJ9onE?p=preview try using `JSON.parse` on your value – Brocco Nov 28 '14 at 19:30
  • so you are saying that the problem is with the way asp.net mvc serializes the date? – Z . Nov 28 '14 at 19:33
  • 1
    Yes, I have come across that before, I'm sure there are plenty of answers on here that can direct you in to solving that issue on the server. – Brocco Nov 28 '14 at 19:37
  • Example fix: http://stackoverflow.com/questions/206384/format-a-microsoft-json-date – Brocco Nov 28 '14 at 19:43

1 Answers1

1

Try

{{ item.CreateDate | msDate | date : 'MM/dd/yyyy' }}

And the filter

app.filter('msDate', function () {
  return function (item) {
    return new Date(parseInt(item.substr(6)));
  };
});

Thanks @Brocco.

Andy Ecca
  • 1,929
  • 14
  • 14