Utilizing angular js filter in the controller for date formatting. A user selects a date from a uib-datepicker-popup
. The goal is to format this date using ISO 8601
(yyyy-mm-dd) date format. Upon logging the user-selected date, the output is as follows:
Sat Aug 20 2016 00:00:00 GMT+0300 (EAT)
After applying the angular $filter as shown below
$filter('date')(new Date(vm.my_date), 'yyyy-mm-dd');
The resulting date appears as
2016-00-20
Check out the code in the controller below
// Logs Sat Aug 20 2016 00:00:00 GMT+0300 (EAT)
console.log(vm.my_date);
var converted = $filter('date')(new Date(vm.my_date), 'yyyy-mm-dd');
// Logs 2016-00-20
console.log(converted);
What could be the issue here?