如何在angularjs控制器中以时间格式转换字符串

时间:2018-11-26 11:58:15

标签: javascript angularjs datetime-format

我的控制器中有一个像这样的数据集

{
"schedule":[{"day":"Monday","start":"15:00:00"},{"day":"Tuesday","start":"16:30:00"}]
}

我认为我想使用input [time]

<div ng-repeat="day in obj.schedule">
 <input  type="time" min="00:00:00" max="23:59:00" placeholder="" ng-model="day.start"/>
</div>

它不起作用,因为它需要一个日期,而不是字符串。

如何在控制器内部将字符串转换为时间?

我尝试过

$scope.start = new Date(obj.start)

但这不起作用

var app = angular.module('myApp', []);
app.controller('mainCtrl', function($scope) {
  $scope.obj = {
    "schedule": [{
      "day": "Monday",
      "start": "15:00:00"
    }, {
      "day": "Tuesday",
      "start": "16:30:00"
    }]
  }
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="mainCtrl">
  <div ng-repeat="day in obj.schedule">
    <input type="time" min="00:00:00" max="23:59:00" placeholder="" ng-model="day.start" />
  </div>
</div>

1 个答案:

答案 0 :(得分:0)

如果您希望得到一个约会,可以尝试以下方法

Dcl2_SsHV2L
Dcl2_SsHV2L
Dcl2_SsHV2L
Dcl1_SsHV2L
gsub("SsHV2L.*","",test)