I'm trying to pass a UTC date as a query string parameter to a Web API method. The URL looks like
/api/order?endDate=2014-04-01T00:00:00Z&zoneId=4
The signature of the method looks like
[HttpGet]
public object Index(int zoneId, DateTime? endDate = null)
The date is coming in as 31/03/2014 8:00:00 PM
but I'd like it to come in as 01/04/2014 12:00:00 AM
My JsonFormatter.SerializerSettings
looks like this
new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
DateTimeZoneHandling = DateTimeZoneHandling.Utc,
DateFormatHandling = DateFormatHandling.IsoDateFormat
};
EDIT #1:
I've noticed when I POST 2014-04-01T00:00:00Z
it will serialize to the UTC DateTime kind in C#. However I've found a work around of doing endDate.Value.ToUniversalTime()
to convert it although I find it odd how it works for a POST but not a GET.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…