显示时间两个日期时间值之间的差 [英] Showing Difference between two datetime values in hours

查看:96
本文介绍了显示时间两个日期时间值之间的差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从数据库中检索两个日期时间值。一旦值被检索,我所需要的两个值之间的差。
对于这一点,我创建了一个时间跨度变量存储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;

现在我需要来显示存储在所述时间跨度变量以小时数而言的差异。
我提到<一个href=\"http://msdn.microsoft.com/en-us/library/system.timespan.totalhours.aspx\">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.

这篇关于显示时间两个日期时间值之间的差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆