I have two moment dates and am calculating the duration by doing the diff between both.
How can I post the duration to the WebAPI controller so that it is automatically deserialize to a C# TimeSpan? When I post "P2DT00H" it will deserialize properly to a TimeSpan but how can I get that format from a moment duration?
Calculate the duration as described in this answer Get the time difference between two datetimes
Define an endpoint like this:
public IHttpActionResult Post([FromBody] TimeSpan ts)
{
// do stuff
return Ok(ts);
}
And post the duration like so:
POST http://localhost/theendpoint HTTP/1.1
Content-Length: 12
Content-Type: application/json
Host: localhost
"00:01:10"
And web api will deserialize it and bind it to the model correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With