0

I'm able to get seconds in Time using AngularJS and its "Interval" option but i was thing about adding milliseconds to the same with 2 digits. Below is the code. can anyone tell me on how to add milliseconds to it.

AngularJs Code

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>

Update - On how i found the solution.

I just did the following changes. Thanks to Pranjal

AngularJS Code

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 Answer 1

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>
Sign up to request clarification or add additional context in comments.

2 Comments

but do you have any idea how to convert it to 12hr Format?
Instead of "HH" in capital, use "hh" in small letters. <span>{{CurrentDate | date:'hh:mm:ss:sss'}}</span>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.