I'm making a timer that counts up. A base time is created and then the difference between now and the base time is calculated.
I then make that difference a date, turn it into a string and extract the time in seconds, minutes and hours from it.
Code looks like this:
$scope.time = Date.now() - timeStart; // total elapsed time in ms
$scope.date = new Date($scope.time);
$scope.preDisplay = $scope.date.toUTCString();
$scope.timeDisplay = $scope.preDisplay.match(/\d+:\d+:\d+/);
The matches (
.match) return an array of matching elements. Try accessing it using the first
$scope.timeDisplay = $scope.timeDisplay;