How to pass a datetime parameter?

后端 未结 10 1694
暗喜
暗喜 2020-11-29 01:56

How to pass UTC dates to Web API?

Passing 2010-01-01 works fine, but when I pass a UTC date such as 2014-12-31T22:00:00.000Z (with a time c

10条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-29 02:57

    It used to be a painful task, but now we can use toUTCString():

    Example:

    [HttpPost]
    public ActionResult Query(DateTime Start, DateTime End)
    

    Put the below into Ajax post request

    data: {
        Start: new Date().toUTCString(),
        End: new Date().toUTCString()
    },
    

提交回复
热议问题