本文介绍了DateTime不相等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下一个代码:

DateTime endTime = DateTime.Now.AddDays(30);
InsertIntoDatabase(endTime);
var row = Db.SelectRow("select endTime from MyTable Where @column=myval", columnValue);
Assert.Equal(row["endTime"], endTime); // This is false! Why?

Assert为false。
由于某些原因,日期在毫秒之间是不同的。为什么?

Assert is false.And dates are different for some reason on milliseconds. Why???

endTime:

Date    {7/17/2015 12:00:00 AM} System.DateTime
        Day 17  int
        DayOfWeek   Friday  System.DayOfWeek
        DayOfYear   198 int
        Hour    1   int
        Kind    Unspecified System.DateTimeKind
        Millisecond 370 int
        Minute  21  int
        Month   7   int
        Second  27  int
        Ticks   635726928873700000  long
+       TimeOfDay   {01:21:27.3700000}  System.TimeSpan
        Year    2015    int

行[endTime]:

row["endTime"]:

Date    {7/17/2015 12:00:00 AM} System.DateTime
        Day 17  int
        DayOfWeek   Friday  System.DayOfWeek
        DayOfYear   198 int
        Hour    1   int
        Kind    Local   System.DateTimeKind
        Millisecond 371 int
        Minute  21  int
        Month   7   int
        Second  27  int
        Ticks   635726928873716049  long
+       TimeOfDay   {01:21:27.3716049}  System.TimeSpan
        Year    2015    int

WHY ???

推荐答案

也许将有所帮助。

您还可以使用Datetime2进行SQL

you can also use Datetime2 for SQL

这篇关于DateTime不相等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 10:58