Angular 2 and Express Date format MongoDB Angular 2 and Express Date format MongoDB mongoose mongoose

Angular 2 and Express Date format MongoDB


I'm using moment.js (http://momentjs.com) for all my date formatting

user.component.ts:

formattedDate(date) {    return moment(date).format("DD/MM/YYYY HH:mm:ss")}

user.component.html:

{{ formattedDate(user.createdAt) }}


I got it by changing the @YosvelQuintero answer doing:

user.component.html:

{{ stringAsDate(user.createdAt) | date:'dd MM yy HH:mm:ss' }}

user.component.ts:

stringAsDate(dateStr: string) {  return new Date(dateStr);}

Reference of the issue:https://github.com/angular/angular/issues/6336


Using Angular2 you can specify a date format DatePipe.

Code for your template:

{{ user.createdA | date:'MM dd yy HH:mm:ss' }}   // output is '06/02/2016, 14:20:27'

And here you have a plunker with the solution working.

Note: This pipe uses the Internationalization API. Therefore it is only reliable in Chrome and Opera browsers.