0

I retrieve the data from MongoDB,and it contains date, but the date is String format. I'm trying to use following codes to format the date:

var str = data.date;// assume that is 2002/2/2
var date = new Date(str);
console.log(date);

However the output is :Sat Feb 02 2002 00:00:00 GMT+1100 (AEDT) How can I make the output become the YYYY/MM/DD? Many thanks .

Tarun Dugar
  • 8,921
  • 8
  • 42
  • 79
RMITcoder
  • 5
  • 1
  • possible duplicate of [How to format date in angularjs](http://stackoverflow.com/questions/22392328/how-to-format-date-in-angularjs) – Allmighty Jul 16 '15 at 07:48
  • possible duplicate: http://stackoverflow.com/q/28271904/2460773 . consider using a js libary such as momentJS http://momentjs.com/ – Nitsan Baleli Jul 16 '15 at 07:49

1 Answers1

0

You can easily use a date filter do that in your HTML Template:

{{date | date: 'YYYY/MM/DD'}}

Change your controller code to:

var str = data.date;
$scope.date = new Date(str);

so that 'date' can be binded to the HTML template as explained.

Tarun Dugar
  • 8,921
  • 8
  • 42
  • 79