AngularJs从人类可读的日期得到时间戳 [英] AngularJs get Timestamp from a human readable date
本文介绍了AngularJs从人类可读的日期得到时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有角JS的方式从通过形式获得的日期得到时间戳?
Is there a way in angular JS to get Timestamp from a date obtained by a form?
<label for="start">From:</label>
<input type="date" ng-model="startDate" />
我将在该指令将这一数据写?我没有找到关于这一具体问题任何事情,
问候
What will I have to write in the directive to transform this data? I didn't find anything about this particular issue, Regards
推荐答案
使用一个指令值从视图中更改模型。
Use a directive to change the value from view to model.
http://jsfiddle.net/bateast/Q6py9/1/
angular.module('app', [])
.directive('stringToTimestamp', function() {
return {
require: 'ngModel',
link: function(scope, ele, attr, ngModel) {
// view to model
ngModel.$parsers.push(function(value) {
return Date.parse(value);
});
}
}
});
这篇关于AngularJs从人类可读的日期得到时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文