Correct insert DateTime from c# to mongodb

后端 未结 4 770
情歌与酒
情歌与酒 2020-12-29 13:52

I try to insert local time in MongoDB

var time = DateTime.Now; // 03.05.2014 18:30:30

var query = new QueryDocument
{
   { \"time\", nowTime}
};

collection         


        
4条回答
  •  攒了一身酷
    2020-12-29 14:49

    Just define the "Kind" of the DateTime by the "BsonDateTimeOptions" attribute and set it to local:

    [BsonDateTimeOptions(Kind = DateTimeKind.Local)]
    public DateTime SomeDateProperty {get;set;}
    

提交回复
热议问题