Datetime issues with Mongo and C#

后端 未结 2 2157
不知归路
不知归路 2021-01-01 22:06

I\'m having an issue with saving and retrieving dates with Mongo using the c# driver. For some reason it it\'s truncating the ticks.

When I store this:



        
2条回答
  •  太阳男子
    2021-01-01 22:44

    Here's an extension you could use :)

    public static class MongoDateComparison
    {
        private static int precisionInMilliseconds = 1000;
        public static bool  MongoEquals(this DateTime dateTime, DateTime mongoDateTime)
        {
            return Math.Abs((dateTime - mongoDateTime).TotalMilliseconds) < precisionInMilliseconds;
        }
    }
    

提交回复
热议问题