C#中的日期时间问题 [英] datetime problem in C#

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

问题描述

我在C#中使用WPF.我有两个日期选择器.我想第一个日期选择器天减去第二个日期选择器.而且第一个日期选择器的第一个日期选择器天数较少,因此消息框显示错误.那我该怎么办.

i''m working in WPF in C#. i have two datepicker. and i want first datepicker days subtract 2nd datepicker. And first datepicker days is less for 2nd datepicker so message box show error. So what can i do.

推荐答案

您提到一个消息框.我建议显示一条错误消息,或类似的原因来显示错误(文本框上有错误和工具提示的红色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


这篇关于C#中的日期时间问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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