Reputation: 5162
When the following setter receives endDate="2015-05-01T00:00:00+08:00"
in a json string, the time zone offset is lost and the value is 2015-05-01T00:00:00
. I need the date to adjust to UTC when the offset is lost.
The object is deserialized automatically within a WebAPI Formatter using JSON.NET
private DateTime? _endDate;
public DateTime? endDate
{
get {
//...
}
set { _endDate = value; }
}
What's wrong or how can I get the UTC time instead?
Upvotes: 2
Views: 632
Reputation: 11480
I believe your intent would be the following:
private DateTime? date;
public DateTime? Date
{
get
{
if(date != null)
return TimeZoneInfo.ConvertToUtc(date);
return date;
}
}
That would create a Property that will take a date format, then will convert it to a valid UTC Format. However, if you require more minute control you'll want to rethink the approach. You can find more information here.
Hopefully that is what your actually asking, if not I'll delete the answer.
Upvotes: 2