Send JQuery JSON to WCF REST using date

前端 未结 6 533
慢半拍i
慢半拍i 2020-12-08 08:54

I know that are a lot of posts about consuming a WCF REST through JQuery/JSON, but I can\'t get it to work. I\'m currently stuck at a date parameter. Below is my C# method:<

6条回答
  •  猫巷女王i
    2020-12-08 09:15

    There should be a generic method to format the date properly before passing to the wcf.

    The method could look like this:

    var dateToWcf = function(input)
    {
        var d = new Date(input); 
        if (isNaN(d)) return null;     
        var formattedDate = { date : "/Date(" + d.getTime() + ")/" };
        return formattedDate;
    }
    

    However now if you post it would append the offset value based on the actual timezone from where you are posting.So in order to avert this you could then adjust the offset accordingly.

    var formattedDate = { date: "/Date(" + d.getTime() + d.getGMTOffset() + ")/" };
    

提交回复
热议问题