<small id='4zmxZ'></small><noframes id='4zmxZ'>

<i id='4zmxZ'><tr id='4zmxZ'><dt id='4zmxZ'><q id='4zmxZ'><span id='4zmxZ'><b id='4zmxZ'><form id='4zmxZ'><ins id='4zmxZ'></ins><ul id='4zmxZ'></ul><sub id='4zmxZ'></sub></form><legend id='4zmxZ'></legend><bdo id='4zmxZ'><pre id='4zmxZ'><center id='4zmxZ'></center></pre></bdo></b><th id='4zmxZ'></th></span></q></dt></tr></i><div id='4zmxZ'><tfoot id='4zmxZ'></tfoot><dl id='4zmxZ'><fieldset id='4zmxZ'></fieldset></dl></div>

      <bdo id='4zmxZ'></bdo><ul id='4zmxZ'></ul>
      <tfoot id='4zmxZ'></tfoot>
    1. <legend id='4zmxZ'><style id='4zmxZ'><dir id='4zmxZ'><q id='4zmxZ'></q></dir></style></legend>

      来自json对象的Angular.js格式日期

      时间:2023-09-05

          • <bdo id='YbJII'></bdo><ul id='YbJII'></ul>

              <tfoot id='YbJII'></tfoot>

                <tbody id='YbJII'></tbody>
            1. <small id='YbJII'></small><noframes id='YbJII'>

              <legend id='YbJII'><style id='YbJII'><dir id='YbJII'><q id='YbJII'></q></dir></style></legend>
              • <i id='YbJII'><tr id='YbJII'><dt id='YbJII'><q id='YbJII'><span id='YbJII'><b id='YbJII'><form id='YbJII'><ins id='YbJII'></ins><ul id='YbJII'></ul><sub id='YbJII'></sub></form><legend id='YbJII'></legend><bdo id='YbJII'><pre id='YbJII'><center id='YbJII'></center></pre></bdo></b><th id='YbJII'></th></span></q></dt></tr></i><div id='YbJII'><tfoot id='YbJII'></tfoot><dl id='YbJII'><fieldset id='YbJII'></fieldset></dl></div>
                本文介绍了来自json对象的Angular.js格式日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我的 json 响应如下所示:

                My json response look like this:

                [{"Id":"dab4580b-e24d-49f8-9fd5-2e968b10d3b5","Title":"MVVM-Sidekick 入精","CreatedOn":"/Date(1390272893353)/","IsChecked":false},{"Id":"66a0f134-e240-4cc4-96fa-ac3807853ca7","Title":"Windows Phone 开发入精","CreatedOn":"/Date(1390018447080)/","IsChecked":false}]
                

                CreatedOn"日期采用这种格式:'/Date(1390272893353)/'

                the "CreatedOn" date is in this kind of format: '/Date(1390272893353)/'

                当我将此结果绑定到 html 表格时,日期无法格式化:

                when I bind this result to html table, the date cannot be formatted:

                <td>{{item.CreatedOn | date: 'yyyy-MM-dd HH:mm'}}</td>
                

                仍然给我:

                /日期(1390272893353)/

                /Date(1390272893353)/

                我不想更改服务器端的任何代码(不要修改 json 字符串),格式化此日期的最佳方式是什么?

                I don't want to change any code on the server side (don't modify the json string), what's the best way to format this date?

                推荐答案

                一种选择是编写另一个过滤器并将其放入链中.例如:

                One option is to write another filter and put it in the chain. E.g.:

                app.filter("mydate", function() {
                    var re = //Date(([0-9]*))//;
                    return function(x) {
                        var m = x.match(re);
                        if( m ) return new Date(parseInt(m[1]));
                        else return null;
                    };
                });
                

                基本上它使用正则表达式来解析字符串并生成一个 Date(如果格式与显示的格式不同,则必须调整正则表达式).

                Basically it uses the regular expression to parse the string and make a Date (if the format is different than the one shown, you will have to tweak the regular expression).

                将其用作:

                <td>{{item.CreatedOn | mydate | date: 'yyyy-MM-dd HH:mm'}}</td>
                

                这篇关于来自json对象的Angular.js格式日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何成功地将图像嵌入 HTML 以在 webmail 客户端中 下一篇:JavaScript 格式数字,始终为 3 位数字

                相关文章

                最新文章

                1. <small id='EcKQ9'></small><noframes id='EcKQ9'>

                  • <bdo id='EcKQ9'></bdo><ul id='EcKQ9'></ul>

                    <i id='EcKQ9'><tr id='EcKQ9'><dt id='EcKQ9'><q id='EcKQ9'><span id='EcKQ9'><b id='EcKQ9'><form id='EcKQ9'><ins id='EcKQ9'></ins><ul id='EcKQ9'></ul><sub id='EcKQ9'></sub></form><legend id='EcKQ9'></legend><bdo id='EcKQ9'><pre id='EcKQ9'><center id='EcKQ9'></center></pre></bdo></b><th id='EcKQ9'></th></span></q></dt></tr></i><div id='EcKQ9'><tfoot id='EcKQ9'></tfoot><dl id='EcKQ9'><fieldset id='EcKQ9'></fieldset></dl></div>
                    <legend id='EcKQ9'><style id='EcKQ9'><dir id='EcKQ9'><q id='EcKQ9'></q></dir></style></legend>

                    <tfoot id='EcKQ9'></tfoot>