且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C#中的日期时间问题

更新时间:2023-11-26 16:02:58

您提到一个消息框.我建议显示一条错误消息,或类似的原因来显示错误(文本框上有错误和工具提示的红色broder).同时,禁止用户按确定"按钮.用户并不真正喜欢消息框.一些设计师会尽一切可能避免出现消息框.
You mention a message box. I would recommend displaying an error message, or some similar why of showing there is an error (red broder on textboxes with errors and a tool tip). At the same time disable the user from pressing the OK button. Users are not real fond of message boxes. Some designers do everything they can to avoid message boxes.


我不知道您确切拥有什么日期选择器,但他们都应该具有类似类型的Value属性System.DateTime
http://msdn.microsoft.com/en-us/library/system.datetime.aspx [ ^ ].

并且此类型定义了减法运算.因此,如果您有两次,则可以找到如下所示的差异:
I don''t know what exactly date picker do you have, but they all should have something like Value property of the type System.DateTime,
http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^].

And this type has subtraction operation defined. So, if you have two times, the difference can be found like this:
System.DateTime t1 = //...
System.DateTime t2 = //...
System.TimeSpan = t2 - t1; //as simple as that; t1 - t2 is also valid



最后,查看System.TimeSpan结构以了解其含义:
http://msdn.microsoft.com/en-us/library/system.datetime.aspx [ ^ ].

—SA



Finally, look at System.TimeSpan structure to see what is that:
http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^].

—SA