datetimepicker差异值在文本框中出现错误 [英] datetimepicker difference value in days coming wrong in textbox
本文介绍了datetimepicker差异值在文本框中出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这里,我试图区分两个datetimepicker值并在文本框中显示输出。代码如下所述。
Here, I am trying to take difference of two datetimepicker values and show output in a textbox. code is mentioned below.
DateTime start = dateTimePicker2.Value;
DateTime finish = dateTimePicker3.Value;
TimeSpan NoDays = finish - start;
int TotalDays = NoDays.Days;
textBox4.Text = ((int)Math.Ceiling(NoDays.TotalDays)).ToString();
虽然两个日期之间只有一天的差异,但是执行输出的数字就像文本框中的43205一样。
请建议。
While executing output is coming in numbers like 43205 in textbox even if there is a single day difference between both the dates.
Please suggest.
推荐答案
首先,检查你是否有正确的DateTimePickers - 使用VS默认名称是一个错误的好方法,我注意到你至少有三个DTP控件你的表格。如果你使用错误的两个,那么问题可能是一个很大的数字!
去设计师,并重命名两个DTP - dtpStartDate和dtpEndDate是好名字 - 然后看看你的代码,看看那里的名字是否也有变化......
First off, check you have the right DateTimePickers - using VS default names for everything is a good recipe for mistakes, and I notice that you have at least three DTP controls on your form. If you are using the wrong two, then the problem is likely to be a large number!
Go to the designer, and rename the two DTP's - dtpStartDate and dtpEndDate are good names - then look at your code and see if the names there changed as well...
这篇关于datetimepicker差异值在文本框中出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文