Handling MongoDB's ISODate() when attempting to parse a serialized JSON string

前端 未结 6 1793
庸人自扰
庸人自扰 2021-02-07 11:00

I\'m using MongoDB via the official C# driver with an ASP.NET MVC web site.

I have the following C# model:

public class Contact
{
    public ObjectId Id          


        
6条回答
  •  一整个雨季
    2021-02-07 11:16

     var IDict = v as IDictionary;
                            var dict = IDict.ToDictionary(x => x.Key, x => x.Value);
                            var dateVal = dict["$date"];
                            var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                            var dateTimeVal = epoch.AddMilliseconds(Convert.ToDouble(dateVal));
    

提交回复
热议问题