Custom JavaScriptConverter for DateTime?

前端 未结 10 755
走了就别回头了
走了就别回头了 2020-12-02 19:18

I have an object, it has a DateTime property... I want to pass that object from an .ashx handler back to a webpage via AJAX/JSON... I don\'t want to use 3rd party controls..

10条回答
  •  不思量自难忘°
    2020-12-02 19:34

    the answer is: you can't use JavaScriptConverter this way... it doesn't have the capabilities.

    but for reference:

    How do I format a Microsoft JSON date? http://blog.stevenlevithan.com/archives/date-time-format

    If you care, what I ended up doing was adding a method to the javascript string prototype to make this easier for me in code:

    String.prototype.dateFromJSON = function () {
        return eval(this.replace(/\/Date\((\d+)\)\//gi, "new Date($1)"));
    };
    

    this is still painful to use in the meat of the code because you have to constantly call dateFromJSON() all over the place... which is dumb.

提交回复
热议问题