javascript - Converting date using Angular JS filter fails -
i using angular js filter format date on controller. user selects date uib-datepicker-popup
. date want formatted using iso 8601
(yyyy-mm-dd) date format. log date picked user ,
sat aug 20 2016 00:00:00 gmt+0300 (eat)
however use angular $filter this
$filter('date')(new date(vm.my_date), 'yyyy-mm-dd');
and wind date
2016-00-20
here code on controller
// 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 doing wrong?
when write mm
in filter filter thinks mean minutes
that.
filter understand m
s need uppercase understands mean month
.
changing filter from:
var converted = $filter('date')(new date(vm.my_date), 'yyyy-mm-dd');
to
var converted = $filter('date')(new date(vm.my_date), 'yyyy-mm-dd');
would fix issue.
Comments
Post a Comment