Hello.
You can make use of the getTime function of javascript.
Just call it when you start your activity and update it as long as your activity is running.
The flow is like this. When you start your activity, you save the date in the startTime variable.
Then we have a function which calls itself every 100ms called UpdateTimer.
It stores the date in the CurrentTime variable then computes the difference between CurrentTime and startTime.
The difference is the time consumed by your activity.
var startTime;
$scope.StartTimer = function()
{
startTime = new Date().getTime();
}
$scope.UpdateTimer = function()
{
var currentTime = new Date().getTime();
var distance = currentTime - startTime;
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
$scope.view.wdg['valueDisplay-3'].value = $scope.PadZeros(hours) + ":" + $scope.PadZeros(minutes) + ":" + $scope.PadZeros(seconds);
$scope.intervalPromise = $interval($scope.UpdateTimer, 100, 1, true);
}
$scope.PadZeros = function(value)
{
if((value.toString()).length < 2) return "0" + value.toString();
return value;
}
angular.element(document).ready(function () {
$scope.init();
});
$scope.init = function()
{
$scope.StartTimer();
$scope.UpdateTimer();
}