1

I have an date string as : Wed Aug 30 2017 00:00:00 GMT+0530 (IST) and I want to convert it into like this: 2017-8-30

Now I am doing this:

moment($scope.date.selectedDate).format('YYYY-M-DD') and it is giving the right time but throws a warning as :

moment construction falls back to js date

1

3 Answers 3

2

As the input is JS date so you need to pass input format as well. This can be done by:

moment('Wed Aug 30 2017 00:00:00 GMT+0530', 'ddd MMM DD YYYY HH:mm:ss GMT+-HH:mm').format('YYYY-M-DD');

https://jsfiddle.net/o01ktajp/1/

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

Comments

0

Relative to the warning you can refer to this post Deprecation warning: moment construction falls back to js Date. The easiest solution would be to pass the date string in the ISO format.

As for the date, if you simply want to display the date in the UI with that format you can use the 'date' angular filter: https://docs.angularjs.org/api/ng/filter/date.

In your case you could use it like this:

$scope.date.selectedDate | date: 'YYYY-M-DD'

Br,

Comments

0

You can do:

var d = new Date('Wed Aug 30 2017 00:00:00 GMT+0530');

var formated = moment(d).format('YYYY-M-DD');

Comments

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.