I have a date time that is stored in our backend systems like 2019-11-27T00:00:00.
I now want to use that data, that represent the date and time regardless of the timezone, as a part of a JSON document that is shipped to external users.
I'm currently using the Noda Time type Instant to represent the above values.
InstantPattern.CreateWithInvariantCulture("yyyy-MM-ddTHH:mm:ss").Parse("2019-11-27T00:00:00").Value;
When I later want to output the time in the JSON document I would like to convert it to a type that also can represent the time zone for the current object. The time zones are known.
As an example, the above value should be represented like this in the document:
Sweden: 2019-11-27T00:00:00+01:00
Finland: 2019-11-27T00:00:00+02:00
The reason I want to do this is that the date and time in the database represents the time that an event occurs in local time for the current data consumer. An example would be a "Black Friday" sale that starts midnight of the actual country the sale is in, not when midnight occurs in UTC or likewise. By setting the time zone information in the output JSON I can guarantee that the consumers of the data get the correct information.
All my attempts to use the ZonedDateTime from an Instant, the Instant is treated as UTC time and the output becomes incorrect. There is probably something I'm missing, but I'm unfortunately stuck.
My questions are:
- is NodaTime the correct Library for this?
- is Instant the correct data type for the database values?
- is ZonedDateTime the correct way of working?
- how can I convert a Instant to any other type that can contain TimeZone information?
Thank's in advance.