使用C#驱动程序从蒙戈收集获取的DateTime [英] Get DateTime from mongo collection using c# driver

查看:139
本文介绍了使用C#驱动程序从蒙戈收集获取的DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下对象:

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; }
}

当我保存对象,以蒙戈的日期出现右侧(日期时间字段包含我插入正确的日期)。 。然而,当我拉这个对象,我得到不同的时间(2-3小时)

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).

例如:
我保存StartWorkTime = 2012年6月26日对象为10:00:00 am ,渐渐从集合StartWorkTime等于对象2012年6月26日的 7:00:00点然后当
这使处理时间错误的计算。

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.

我使用的是最新的C#驱动程序(1.4.2.4500)和运行代码和对蒙戈服务器在同一台机器。

I'm using the latest c# driver (1.4.2.4500) and running both code and the mongo server on the same machine.

什么会导致不同?

谢谢!

推荐答案

挖了一下之后,我发现这个帖子:
http://alexmg.com/post/2011/09/30/DateTime-precision-with-MongoDB-and-the-C- Driver.aspx

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

我需要标记与[BsonDateTimeOptions(KIND = DateTimeKind.Local)]属性。

I needed to mark the DateTime property with [BsonDateTimeOptions(Kind = DateTimeKind.Local)] attribute

这篇关于使用C#驱动程序从蒙戈收集获取的DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆