angular获取时间

时间:2021-03-26 08:39:44
获取24小时制的时间
<h1>
{{time}}
</h1>
<script>
angular.module('app', [])
.controller('ctrl', function($scope, $interval, $http) {
$scope.time = 0;
$interval(function() {
$scope.time = new Date().toLocaleTimeString().replace(/^\D*/, '');
}, 1000);
}
</script>

获取12小时制的时间

<h1>
{{time}}
</h1>
<script>
angular.module('app', [])
.controller('ctrl', function($scope, $interval, $location, $http) {
$scope.time = 0;
$interval(function() {
$scope.time = new Date().toLocaleTimeString();
}, 1000);
}
</script>