【问题标题】:AngularJS: Filter date with sql date string formatAngularJS:使用 sql 日期字符串格式过滤日期
【发布时间】:2015-10-03 08:32:28
【问题描述】:

我需要添加一个日期过滤器,它的日期属性为日期字符串值(“2015-10-15T20:00:00.000Z”)。这是一个巨大的列表,所以我不能将每个对象都转换为 Date 然后过滤。我相信有任何替代方法可以做到这一点。

【问题讨论】:

    标签: sql angularjs angularjs-ng-repeat datefilter


    【解决方案1】:

    试试这个过滤器:

    angular.module('yourmodule').filter('datetime', function($filter) {
        return function(input) {
            var t = input.split(/[- :]/);
    
            // Apply each element to the Date function
            var d = new Date(t[0], t[1] - 1, t[2], t[3], t[4], t[5]);
            console.log(d);
            return d;
        };
    
    });
    

    【讨论】:

    • 我实际上需要过滤掉没有今天日期的日期范围。我添加了一个 ng-show,其中一个函数分别传递 fromDate 和 toDate。 new Date("2015-10-15T20:00:00.000Z") 将给出 JS 日期对象并返回相应的值。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-14
    相关资源
    最近更新 更多