且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

AngularJs 从人类可读的日期获取时间戳

更新时间:2022-12-18 09:54:38

使用指令将值从视图更改为模型.

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);
                });
            }
        }
    });