Anuja Patil Anuja Patil - 9 months ago 60
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.

Answer Source

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

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

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