I have the following object:
public class QueueItem
{
public long _id { get; set; }
public SiteMapRequestState State { get; set; }
public int WorkerId { get; set; }
public DateTime QueuedTime { get; set; }
public DateTime StartWorkTime { get; set; }
}
When I save the object to mongo the date appear right (the DateTime fields contains the correct date that I inserted). However when i pull this object I get different time (-3 hours).
For example:
I save the object with StartWorkTime = 6/26/2012 10:00:00 AM, then when getting the object from the collection StartWorkTime equals to 6/26/2012 7:00:00 AM.
This make the calculation of process time wrong.
I’m using the latest c# driver (1.4.2.4500) and running both code and the mongo server on the same machine.
What can cause the difference?
Thanks!
After digging a bit i found this posts:
http://alexmg.com/post/2011/09/30/DateTime-precision-with-MongoDB-and-the-C-Driver.aspx
http://www.mongodb.org/display/DOCS/CSharp+Driver+Serialization+Tutorial#CSharpDriverSerializationTutorial-DateTimeSerializationOptions
I needed to mark the DateTime property with [BsonDateTimeOptions(Kind = DateTimeKind.Local)] attribute