Display Current DateTime in SQL format (yyyy-MM-dd HH:mm:ss) in AngularJS

Last Reply 3 months ago By dharmendr

Posted 3 months ago

How to pass current date time in sql format in angularjs and insert the current date using post method in angularjs and also in web api

For Eg :

The required output format is 2019-05-28 09:30:08.730

 

Posted 3 months ago

Hi skp,

Check this example. Now please take its reference and correct your code.

HTML

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.8/angular.min.js"></script>
    <script type="text/javascript">
        var app = angular.module('MyApp', []);
        app.controller('MyController', function ($scope) {
            $scope.DateTime = new Date().toISOString().slice(0, 19).replace('T', ' ');
        });
    </script>
</head>
<body>
    <div ng-app="MyApp" ng-controller="MyController">
        {{DateTime}}
    </div>
</body>
</html>

Demo