POSTing a DateTime from Android to a WCF RESTful JSON Service

前端 未结 4 1222
醉话见心
醉话见心 2021-02-10 09:11

I\'m trying to send a DateTime as a parameter to a method exposed over a WCF RESTful service with JSON encoding. The request looks like this:

POST h         


        
4条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-10 09:19

    The correct format for posting dates to WCF service is using: /Date(53244000000)/ where the number in brackets is the number of milliseconds since 1970 UTC Midnight.

    Date dt = new Date();
    long date = Date.UTC(dt.getYear(), dt.getMonth(), dt.getDay(), dt.getHours(),dt.getMinutes(), dt.getSeconds());
    String senddate = "/date("+date+")/";
    

    And then use it as below

    inputparam.put("DateTime", datetime);
    

提交回复
热议问题