Reputation: 447
I have a wep api hosted in Azure which is .NET Core. It is a simple CRUD api for now. I have an interesting problem that I could not find or understand the reason.
In my api, there is a DateTime property as usual. When I post a data to api, the time offset disappears in server side.
"dateTime":"2016-08-29T05:13:21.931+03:00" the +03:00 turns into 00:00
Can anyone explain the reason and the solution?
{
"content":"Test Data",
"location":{
"name":"Some Location",
"address":"",
"latitude":41.0920448,
"longitude":28.9444847
},
"owner":{
"userName":"Some User",
"name":null,
"registrationType":0,
"profilePictureURL":null
},
"dateTime":"2016-08-29T05:13:21.931+03:00",
"createTime":"2016-08-29T05:13:21.7791051+00:00",
"rankingPoint":0.0
}
Upvotes: 0
Views: 704
Reputation: 17485
1.First of all your azure service is runnig on 00:00 Timezone.
if you look at DateTime structure it has special property called Kind. During serialization/deserialization this property take into consideration.
DateTime dt = DateTime.Now; // dt.Kind ( Local , Utc etc).
The way serialization works it look this property at server side Json Serialziation setting. This option is also no help.
3. Simple and Best Solution I found is to use DateTimeOffset instead of DateTime.
Upvotes: 1