How to handle json DateTime returned from WCF Data Services (OData)

前端 未结 8 820
情书的邮戳
情书的邮戳 2020-12-01 11:19

I believe I am missing something obvious here. When I request a JSON response from an OData service I get a different result for the DateTime properties than I do when I req

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 11:43

    If this may help, I was facing the same problem and I ended to implement something like this, not so elegant but it works.

    String.prototype.DateWCF = function(dateformat) {
        return new Date(parseInt(this.match(/\/Date\(([0-9]+)(?:.*)\)\//)[1])).format(dateformat);
    };
    

    then on $.ajax success:

            success: function(data) {
                $.each(data, function() {
                    var hello = this.DateTimeProperty.DateWCF('dd-MM-yyyy'));
                });
            }
    

    I hope this may be helpful.

提交回复
热议问题