c# - date field weird behaviour -


I have a model that represents a Mongo document with a date field.

  class model {... [BSN ("date-crated")] [BS-endime option (type = datetime link local)] dated the date of public date {get; Set; } ...}  

I know that in the time of UTC it is assumed that the stock is stored, so I will send it BsonDateTimeOptions Use the attribute.

When I make an instance of the model and store it in Mongo, it works as expected. However, when I receive data from an external source (customer for my service) and is interested in my model, it stores local time.

The compiler 2 shows the same values ​​for different instances (before putting them on Mongo) but for the first time in DB, UTC and the other are deposited in local time.

I believe that you need it before assigning your Jason Percept data in a way For, whether it is local or UTC will tell the Mongo driver what he shows so that he does not incorrectly convert in any other format before saving.

  someDate = DateTime.SignifyKind (someDate, DateTimeKind.Utc)  

Comments