Nick Nick - 1 year ago 42
C# Question

ISO8601 direct DateTime parse incorrect by single day

I am trying to pass two datetime fields (start date and end date) to my webapi server in which the ISO8601 format date string in my javascript appears to be passing correctly, but the server is interpretting both dates incorrectly by a single day.


results in:

Start Date ='2016-09-02 00:00:00'

End Date = '2016-10-01 00:00:00'

public HttpResponseMessage Get(DateTime? dateLodgedStart, DateTime? dateLodgedEnd) {
//Do stuff

Any thoughts?

Answer Source

Because you are in GMT+10 and you are parsing dates in "Zulu Time" - i.e. GMT+0 then the parser is automatically adding the 10 hours for you.

If we use C# for the parsing then we can see this using DateTimeOffset.Parse:

var startDate =

var endDate =


This produces:

2016/09/02 00:00:00 +10:00
2016/09/30 23:59:59 +10:00

There does still appear to be an odd rounding error on your end date though.