Reputation: 2457
I'm running into an issue where I'm trying to parse a datetime string from Json.
I'm saving the following date via json: 04/01/1990
- it's serializing that datetime like this: "1990-04-01T04:00:00.000Z"
However its returning 3/31/1990 When I then try to parse that string dob back into a datetime object like this:
var dob = DateTime.MinValue;
DateTime.TryParse(DOB, CultureInfo.CurrentCulture, DateTimeStyles.AssumeUniversal, out dob);
I've also tried (with no luck):
var dob = DateTime.MinValue;
DateTime.TryParse(DOB, out dob);
I can't figure out how to correctly parse this datetime to the proper original date.
Upvotes: 0
Views: 412
Reputation: 1315
.NET is converting the time to your local time. You can call ToUniversalTime()
to convert it back to UTC.
Alternatively, you can use DateTimeOffset
to keep the date relative to UTC.
Upvotes: 2