我有以下对象:
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; }
}
当我将对象保存到 mongo 时,日期显示正确(DateTime 字段包含我插入的正确日期)。然而,当我拉动这个物体时,我得到了不同的时间(-3 小时)。
例如: 我使用 StartWorkTime = 6/26/2012 10:00:00 AM 保存对象,然后从集合中获取对象时 StartWorkTime 等于 6/26/2012 7:00:00上午。 这使得过程时间的计算错误。
我正在使用最新的 c# 驱动程序 (1.4.2.4500) 并在同一台机器上运行代码和 mongo 服务器。
什么会导致差异?
谢谢!
最佳答案
在深入挖掘之后,我发现了这个帖子: http://alexmg.com/post/2011/09/30/DateTime-precision-with-MongoDB-and-the-C-Driver.aspx
我需要用 [BsonDateTimeOptions(Kind = DateTimeKind.Local)] 属性标记 DateTime 属性
关于c# - 使用 C# 驱动程序从 mongo 集合中获取 DateTime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11202753/