比较texbox中的时间 [英] Compare timing in texbox

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

问题描述

string timeFrom =;



string timeTo =;



你如何比较在texbox中的两个时间之间?

string timeFrom = "";

string timeTo = "";

How you compare between two timing in texbox?

推荐答案

尝试> TimeSpan变量= timeTo - timeFrom;


首先,不要使用字符串作为时间对象,使用 System.DateTime ,解决方案1中显示的方式。

如果你真的需要从某个字符串中解析时间,请使用名为 Parse,TryParse,ParseExact,TryParseExact 的方法之一:

< a href =http://msdn.microsoft.com/en-us/library/System.DateTime_methods%28v=vs.110%29.aspx> http://msdn.microsoft.com/en-us/library /System.DateTime_methods%28v=vs.110%29.aspx [ ^ ]。



但是,尽量避免这种常见的谬误困扰着许多开发人员这些天:使用表示数据的字符串而不是数据。我不确定你真的需要解析字符串。你可以使用某种 DateTimePicker 。这取决于你使用的UI框架/库。



顺便说一下,如果你写 TextBox ,它没意思。你认为只有一种这样的名字吗?请注明全名类型。



-SA
First of all, don't use strings for time objects, use System.DateTime, the way shown in Solution 1.
If you really need to parse time from some string, use one of the methods named Parse, TryParse, ParseExact, TryParseExact:
http://msdn.microsoft.com/en-us/library/System.DateTime_methods%28v=vs.110%29.aspx[^].

However, try to avoid this common fallacy haunting many developers these days: using strings representing data instead of data. I'm not sure you really need parsing of strings. You could use some kind of DateTimePicker. It depends on the UI framework/library you use.

By the way, if you write TextBox, it means nothing certain. Do you think there is only one type named like that? No. Full type name, please.

—SA


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

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