显示时间两个日期时间值之间的差
我从数据库中检索两个日期时间值。一旦值被检索,我所需要的两个值之间的差。
对于这一点,我创建了一个时间跨度变量存储2日期值的差异。
I am retrieving two date time values from the database. Once the value is retrieved, I need the difference between the two values. For that, I create a timespan variable to store the difference of the 2 date values.
TimeSpan? variable = datevalue1 - datevalue2;
现在我需要来显示存储在所述时间跨度变量以小时数而言的差异。
我提到TimeSpan.TotalHours但不能因为某种原因应用相同的。
我怎么做?
我使用一个MVC项目C#。我简单的需要显示在小时差值?
Now i need to show the difference which is stored in the Timespan variable in terms of number of hours. I referred to TimeSpan.TotalHours but couldn't apply the same for some reason. How do I do that? I am using C# on a MVC project. I simple need to show the difference value in hours?
编辑:
由于时间跨度是空的,我不能使用总时间属性。现在,我可以做TimeSpanVal.Value.TotalHours使用它
我觉得你很困惑,因为你还没有宣布时间跨度
您已经声明了一个时间跨度?这是一个的可空 时间跨度
。要么删除问号,如果你不需要它为可以为空或使用 variable.Value.TotalHours
。
I think you're confused because you haven't declared a TimeSpan
you've declared a TimeSpan?
which is a nullable TimeSpan
. Either remove the question mark if you don't need it to be nullable or use variable.Value.TotalHours
.