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 .

2

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot, but the output is YYYY/02/DD only the month is correct.
Oh thanks this problem is solved, I'm using yyyy/MM/dd

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.