-2

I have this JSON which I send to an API. This data is saved to a COSMOS DB. Whenever I debug my API and use POSTMAN to send this JSON the DateTime got saved correct in the DB- 2018-12-23T00:00:00+01:00. But when I call the API on the cloud (Azure App Service) with the exact same JSON it subtract 1 day - 2018-12-22T00:00:00+00:00

JSON:

{"FoodGroupId":"snack","FoodItemId":"f5ce9e97-0d0c-4ff4-b8ed-cb0d1bb46ef1","Units":25.0,"ConsumedDate":"2018-12-23T00:00:00+01:00"}
Loc Dai Le
  • 1,661
  • 4
  • 35
  • 70
  • 2
    timezone................ – Mitch Wheat Dec 31 '18 at 00:41
  • I think whatever code you have running server side written under assumption that "today" starts at exactly the same moment of time around the globe. While it is obviously false when you say that aloud it is quite common assumption... I'd recommend reviewing all calls to `DateTime.Date` to see if they make sense. – Alexei Levenkov Dec 31 '18 at 00:47

1 Answers1

2

well, the things in Azure are UTC by default. So when you call API and go DateTime.Now, it is actually DateTime.UtcNow!

To overcome this you can specify time-zone for your appsettings:

<add key="WEBSITE_TIME_ZONE" value="Name of Time Zone (like Australian Eastern Standard Time)"/>

You can also add this in portal under Application Settings tab.

EDIT:- the best option is to save datetimeoffset.

TheVillageIdiot
  • 40,053
  • 20
  • 133
  • 188
  • 1
    Picking on other time zone for server generally will not make things much better - just broken for different set of users... – Alexei Levenkov Dec 31 '18 at 00:48
  • @AlexeiLevenkov not sure if there are multiple time-zones be involved, if that is the case then saving the `datetimeoffset` is a better option. But from the question is looks like timestamp is generated on the server so one timezone will suffice. – TheVillageIdiot Dec 31 '18 at 00:54