0

We are trying to display a normal date time within an angualar databind

{{result.ReceivedDateTime | date:'mediumTime' }}

how ever, the result is coming out as : /Date(1395273600000)/

Im guessing this is JSONS dat time (milliseconds)

Is there an easy way to get this to display a proper formatted date rather than

/Date(1395273600000)/ 

we have tried to google, but cant seem to find the answer, any assistance would be appreciated.

Simon
  • 1,412
  • 4
  • 20
  • 48
  • 1
    Please have a look at this question: http://stackoverflow.com/questions/206384/how-to-format-a-json-date – andyp Apr 01 '14 at 14:15
  • I don't think there is a default way to do this. But parsing the milliseconds is easy in js – Praveen Apr 01 '14 at 14:16

2 Answers2

0

From the messages above, we have the following solution works for angular

{{result.ReceivedDateTime.substring(6, result.ReceivedDateTime.length - 2) | date:'dd/MM/yyyy HH:mm' }}

Will look at creating a custom filter so this can be achieved without the need for inline substring etc

Simon
  • 1,412
  • 4
  • 20
  • 48
0

A filter that I commonly use takes an ISO date & converts it to MS. Then you can use whatever date filter you want from angular

example date:

"2014-04-01 10:16:00"

Filter

.filter('isoToMS', function() {
  return function(input) {
    var ms = Date.parse(input.replace(/-/g,"/"));
    return ms;
  };
})

HTML

{{result.date | isoToMS | date:'dd/MM/yyyy HH:mm'}}

The regex /-/g,"/" within the .replace() is to handle inconsistencies with browsers. Chrome will convert to ms properly with - in the ISO date. But FF will not. They require /. So by replacing all - with /, it works across browsers.


Another Dev on my team prefers a different filter:

.filter('dateToISO', function() {
  return function(input) {
    input = new Date(input).toISOString();
    return input;
  };
})

I haven't tested this one though. I haven't always had great luck using ISO dates with Angular filters (hence why I take an ISO date & convert it to MS in my first solution).

EnigmaRM
  • 7,523
  • 11
  • 46
  • 72
  • I suppose `2014-04-01 10:16:00` isn't the proper ISO (8601) standard. To make it proper, it would be: `2014-04-01T16:16:00.000Z` (second filter converts to this format), which Angular does accept. So either filter would work as expected. – EnigmaRM Apr 01 '14 at 20:11