Anuja Patil Anuja Patil - 1 month ago 6
AngularJS Question

Convert date in another format in angularjs

I have a simple issue. This is my startDate,
$scope.startDate = new Date();

I need the date in "2011-01-01T00:00:00" this format.
Thanks

Answer

As suggested use the $filter built-in service, by passing in to your controller:

angular.module('app')
       .controller('MyCtrl', ['$scope', 'MyService', '$filter', function($scope, MyService, $filter) {
            $scope.onSubmit = onSubmit;

            function OnSubmit() {
                MyService.doSomethingSpecial($filter('date')($scope.date, 'dd/mm/yyyy')); // see supported formats
            }

       });
Comments