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

前端 未结 8 785
情书的邮戳
情书的邮戳 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.

    0 讨论(0)
  • 2020-12-01 11:47

    Using date.js script.Try below

    new Date(parseInt(yourDateValue)).toString("ffffd, dd-MMM-yyyy, hh:mm:ss")
    
    0 讨论(0)
提交回复
热议问题