2016-07-26 216 views
0

使用AngularJS及其“间隔”选项,我能够在时间中获得秒数,但我是关于向2位数字添加毫秒的事情。以下是代码。任何人都可以告诉我如何增加毫秒。如何在AngularJS中以毫秒为单位获取时间

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
<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> 
+0

谢谢哥们它的工作。 – Jeeva

+0

但你有任何想法如何将其转换为12小时格式? – Jeeva

+1

而不是在首都“HH”,用小写字母“hh”。 {{CurrentDate |日期:'hh:mm:ss:sss'}} Pranjal

相关问题