如何将Datetime值与具有特定日期的日期时间的特定文本框进行比较 [英] how to Datetime value compare to particular textbox that have a datetime of particular day
本文介绍了如何将Datetime值与具有特定日期的日期时间的特定文本框进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的文本框中,我指定了特定日期的日期时间。这里我要比较特定的日期时间(在文本框中分配)和系统日期时间..任何人都可以帮助我吗?
提前谢谢:)
解决方案
在c#中有一个名为DateTime.Compare的方法。
读取示例如下所示
DateTime date1 = new DateTime( 2009 , 8 , 1 , 0 , 0 , 0 );
DateTime date2 = new DateTime( 2009 , 8 , 1 , 12 , 0 , 0 );
int result = DateTime.Compare(date1,date2);
字符串关系;
if (结果< 0 )
relationship = 早于;
else if (result == 0 )
relationship = 与;
else
relationship = 晚于;
Console.WriteLine( {0} {1} {2},date1,relationship,date2);
// 该示例显示以下输出:
// 8/1/2009 12:00:00 AM早于8/1/2009 12:00:00 PM
了解更多信息你可以看看msdn
http://msdn.microsoft.com/en-us/library/system.datetime.compare%28v= VS.100%29.aspx
In my textbox i have assigned datetime of particular day. Here am going to compare particular datetime(Assigned in textbox) to System date time.. Can any one help me??
Thanks in advance :)
解决方案
In c# there is a method calledDateTime.Compare.
read the example given below
DateTime date1 = new DateTime(2009, 8, 1, 0, 0, 0); DateTime date2 = new DateTime(2009, 8, 1, 12, 0, 0); int result = DateTime.Compare(date1, date2); string relationship; if (result < 0) relationship = "is earlier than"; else if (result == 0) relationship = "is the same time as"; else relationship = "is later than"; Console.WriteLine("{0} {1} {2}", date1, relationship, date2); // The example displays the following output: // 8/1/2009 12:00:00 AM is earlier than 8/1/2009 12:00:00 PM
for more information you can look msdn
http://msdn.microsoft.com/en-us/library/system.datetime.compare%28v=VS.100%29.aspx
这篇关于如何将Datetime值与具有特定日期的日期时间的特定文本框进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文