本文介绍了我对C#中的datetimepicker工具有疑问.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hai朋友
我对C#中的datetimepicker工具有疑问.

1.
我必须使用一个datetimepicker显示选定日期的剩余天数.
例如今天是2011年4月22日.剩余的日期直到2012年3月31日.
如果是一月,二月和三月,则应显示当年的日期
例如,截至2011年3月31日的剩余天数为2011年3月31日.

2.
使用c#中的datetimepicker工具显示当月的日期.
例如.如果我选择一月,则文本框应告诉days = 31

hai friends
i have a doubt in datetimepicker tool in c#.

1.
I have to display remaining days in a selected date use only one datetimepicker.
for eg today date is 22-apr-2011. remaining days upto 31-mar-2012.
if it is jan, feb and mar it should display the days of current year
for eg 12-jan-2011 remaining days upto 31-mar-2011.

2.
Display the days of current month using datetimepicker tool in c#.
eg. if i am selecting jan month, the textbox should tells days = 31

推荐答案

DateTime start = DateTime.Now;
DateTime end = DateTime.Now.AddDays(25);

TimeSpan span = end - start;
int totalDays = span.TotalDays;




关于问题2.

看看 DateTime.DaysInMonth [ ^ ]

输入年份和月份,它将返回该年份和月份的总天数.




About question 2.

Take a look at DateTime.DaysInMonth[^]

You give it year and month and it will return total days in that year and month.


int daysToGo;
if(yourDateTimePicker.Value.Month > 3){
daysToGo = (new DateTime(yourDateTimePicker.Value.Year + 1,3,31) - yourDateTimePicker.Value).Days;
}
else{
daysToGo = (new DateTime(yourDateTimePicker.Value.Year,3,31) - yourDateTimePicker.Value).Days;
}



2.这应该有帮助:



2. This should help:

yourTextBox.Text = DateTime.DaysInMonth(yourDateTimePicker.Value.Year, yourDateTimePicker.Value.Month).ToString();



这篇关于我对C#中的datetimepicker工具有疑问.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 20:07