如何在AngularJS中获得毫秒的时间

时间:2016-07-26 05:57:13

标签: javascript html css angularjs

我可以使用AngularJS及其“Interval”选项在时间上获得秒数,但我的意思是将2毫秒的毫秒加到毫秒上。下面是代码。任何人都可以告诉我如何为它添加毫秒。

AngularJs代码

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $interval) {
  $scope.theTime = new Date().toLocaleTimeString();
  $interval(function () {
      $scope.theTime = new Date().toLocaleTimeString();
  }, 1000);
});

HTML

<div class="col-lg-2" ng-app="myApp" ng-controller="myCtrl">
<h3 style="color: blue;font-family: cursive;"><b>{{theTime}}</b></h3>
</div>

更新 - 关于我如何找到解决方案。

我刚做了以下更改。感谢 Pranjal

AngularJS代码

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $interval) {
  $scope.theTime = new Date();
  $interval(function () {
      $scope.theTime = new Date();
  }, 1);
});

HTML

<div class="col-lg-2" ng-app="myApp" ng-controller="myCtrl">
<h3 style="color: blue;font-family: cursive;font-size: 20;margin-left: 20;"><b>{{theTime | date:'HH:mm:ss:sss a'}}</b></h3>
</div>

1 个答案:

答案 0 :(得分:1)

<body>
<script type="text/javascript">
    var app = angular.module('MyApp', [])
    app.controller('MyController', function ($scope) {
        $scope.CurrentDate = new Date();
    });
</script>
<div ng-app="MyApp" ng-controller="MyController">

    <span>{{CurrentDate | date:'HH:mm:ss:sss'}}</span>

</div>
</body>