两个值之间的比较 [英] comparison between two values

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

问题描述

我有一个变量;即类型为DateTime&的oDateTime.我从中提取了一个时间,如下所示:

I have a variable; i.e. oDateTime with the type of DateTime & I extracted a time from it as follows:

string.Format("{0:t}", oDateTime); 



现在我的输出是4:00 AM

我的下拉列表控件的值,例如小时为01,02 ..... 12,分钟和分钟为01,02 ... 59. AM,PM用于FormatDropdown控件.

现在,这里的按钮单击事件将检索值&将在控件中将这些值显示为选定值,如下所示:



Now my output is 4:00AM

My dropdownlist controls having the values like 01,02.....12 for Hours and 01,02...59 for Minutes & AM,PM for FormatDropdown control.

Now here on button click event it will retrieve the values & will show those values in controls as selected value as follows:

ddlTFHrs.SelectedValue = String.Format("{0:hh}", oDateTime);

ddlTFMin.SelectedValue = String.Format("{0:mm}", oDateTime);

ddlTFAMPM.SelectedValue = String.Format("{0:tt}", oDateTime);



当我尝试将04与4进行比较时,出现错误.

我可以将时间格式设置为字符串格式为04,还是可以用其他方法比较这两个值?

谢谢



Here I am getting an error when I try to compare 04 with 4.

Can I format the time in string format as 04 or else is there any alternate way to compare these two values?

Thanks

推荐答案

不要将其转换为字符串-总是很麻烦.
而是使用 http://msdn.microsoft.com/en-us/library/system .datetime.timeofday.aspx [ ^ ]
Don''t convert it to a string - that is always a pain.
Instead, use http://msdn.microsoft.com/en-us/library/system.datetime.timeofday.aspx[^]
TimeSpan timeOnly = DateTime.Now.TimeOfDay;


然后,您可以直接将其与您的时间进行比较.


You can then compare this with your time of day directly.


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

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