现在,我这样发布日期:
17:34:14.965
我只有几个小时和几分钟。
怎么做 ?
最佳答案
将String转换为Date对象。然后提取您想要的任何格式
$scope.time = '17:34:14.965';
var timeTokens = $scope.time.split(':');
var newDate= new Date(1970, 0, 1, timeTokens[0], timeTokens[1], timeTokens[2]);
$scope.hourAndMin = $filter('date')(newDate, 'HH:mm');
var app = angular.module("app", []);
app.controller("ctrl", function($scope, $filter) {
$scope.time = '17:34:14.965';
var timeTokens = $scope.time.split(':');
var newDate= new Date(1970, 0, 1, timeTokens[0], timeTokens[1], timeTokens[2]);
$scope.hourAndMin = $filter('date')(newDate, 'HH:mm');
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
{{hourAndMin}}
</div>
关于javascript - 我想从约会中删除秒和毫秒,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41630068/