javascript : 将字符串转换为时间
javascript : convert a string into time
我想在我的代码 "time" 中输入一个字符串 html
<label class="item item-input">
<span class="input-label">Heure de départ </span>
<input type="time" ng-model="heureDepart" id="time" >
</label>
当我直接输入时,它显示了这个错误:
Error: [ngModel:datefmt] Expected `05:01:01` to be a date
http://errors.angularjs.org/1.3.13/ngModel/datefmt?p0=05%3A01%3A01
at REGEX_STRING_REGEXP (ionic.bundle.js:8890)
at Array.<anonymous> (ionic.bundle.js:28634)
at Object.ngModelWatch (ionic.bundle.js:32116)
at Scope.$get.Scope.$digest (ionic.bundle.js:23062)
at Scope.$get.Scope.$apply (ionic.bundle.js:23333)
at HTMLBodyElement.<anonymous> (ionic.bundle.js:20191)
at HTMLBodyElement.eventHandler (ionic.bundle.js:11841)
at triggerMouseEvent (ionic.bundle.js:2865)
at tapClick (ionic.bundle.js:2854)
at HTMLDocument.tapMouseUp (ionic.bundle.js:2927)(anonymous function) @ ionic.bundle.js:20434$get @ ionic.bundle.js:17384$get.Scope.$digest @ ionic.bundle.js:23088$get.Scope.$apply @ ionic.bundle.js:23333(anonymous function) @ ionic.bundle.js:20191eventHandler @ ionic.bundle.js:11841triggerMouseEvent @ ionic.bundle.js:2865tapClick @ ionic.bundle.js:2854tapMouseUp @ ionic.bundle.js:2927
livereload.js?snipver=1:191 WebSocket connection to 'ws://localhost:35729/livereload' failed: WebSocket opening handshake timed out
我该怎么做??
在 jquery 中测试,这是浏览器消息:
The specified value 'hello' does not conform to the required format.
The format is 'HH:mm', 'HH:mm:ss' or 'HH:mm:ss.SSS' where HH is 00-23,
mm is 00-59, ss is 00-59, and SSS is 000-999
您只能使用具有这些格式的字符串。
将您的 ng-model 更改为 heureDepart.value 然后在控制器中执行
$scope.heureDepart = { value: new Date(1970, 0, 1, 05, 01, 01) };
我们终于开始了!!
您需要遵循时间格式。格式为'HH:mm'、'HH:mm:ss'或'HH:mm:ss.SSS' 其中HH为00-23,mm为00-59,ss为00-59,SSS为000-999。
因此,如果我想将其设置为 10:23:24 PM,我会使用 jQuery:
$('#time').val('22:23:24');
这是一个codepen
问题已解决
我在我的控制器中添加了这个:
var heure=$state.params.heure+"";
var h=heure.substring(0, 2);
var m=heure.substring(3, 5);
var s=heure.substring(6, 9);
$scope.heureDepart = { value: new Date(1970, 0, 1, h, m, s ) };
和这个 ng-model="heureDepart.value"
到我的 ng-model
我想在我的代码 "time" 中输入一个字符串 html
<label class="item item-input">
<span class="input-label">Heure de départ </span>
<input type="time" ng-model="heureDepart" id="time" >
</label>
当我直接输入时,它显示了这个错误:
Error: [ngModel:datefmt] Expected `05:01:01` to be a date
http://errors.angularjs.org/1.3.13/ngModel/datefmt?p0=05%3A01%3A01
at REGEX_STRING_REGEXP (ionic.bundle.js:8890)
at Array.<anonymous> (ionic.bundle.js:28634)
at Object.ngModelWatch (ionic.bundle.js:32116)
at Scope.$get.Scope.$digest (ionic.bundle.js:23062)
at Scope.$get.Scope.$apply (ionic.bundle.js:23333)
at HTMLBodyElement.<anonymous> (ionic.bundle.js:20191)
at HTMLBodyElement.eventHandler (ionic.bundle.js:11841)
at triggerMouseEvent (ionic.bundle.js:2865)
at tapClick (ionic.bundle.js:2854)
at HTMLDocument.tapMouseUp (ionic.bundle.js:2927)(anonymous function) @ ionic.bundle.js:20434$get @ ionic.bundle.js:17384$get.Scope.$digest @ ionic.bundle.js:23088$get.Scope.$apply @ ionic.bundle.js:23333(anonymous function) @ ionic.bundle.js:20191eventHandler @ ionic.bundle.js:11841triggerMouseEvent @ ionic.bundle.js:2865tapClick @ ionic.bundle.js:2854tapMouseUp @ ionic.bundle.js:2927
livereload.js?snipver=1:191 WebSocket connection to 'ws://localhost:35729/livereload' failed: WebSocket opening handshake timed out
我该怎么做??
在 jquery 中测试,这是浏览器消息:
The specified value 'hello' does not conform to the required format. The format is 'HH:mm', 'HH:mm:ss' or 'HH:mm:ss.SSS' where HH is 00-23, mm is 00-59, ss is 00-59, and SSS is 000-999
您只能使用具有这些格式的字符串。
将您的 ng-model 更改为 heureDepart.value 然后在控制器中执行
$scope.heureDepart = { value: new Date(1970, 0, 1, 05, 01, 01) };
我们终于开始了!!
您需要遵循时间格式。格式为'HH:mm'、'HH:mm:ss'或'HH:mm:ss.SSS' 其中HH为00-23,mm为00-59,ss为00-59,SSS为000-999。
因此,如果我想将其设置为 10:23:24 PM,我会使用 jQuery:
$('#time').val('22:23:24');
这是一个codepen
问题已解决
我在我的控制器中添加了这个:
var heure=$state.params.heure+"";
var h=heure.substring(0, 2);
var m=heure.substring(3, 5);
var s=heure.substring(6, 9);
$scope.heureDepart = { value: new Date(1970, 0, 1, h, m, s ) };
和这个 ng-model="heureDepart.value"
到我的 ng-model