我对C#中的datetimepicker工具有疑问. [英] i have a doubt in datetimepicker tool in c#.

查看:135
本文介绍了我对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

推荐答案

DateTimePicker类,您可以自定义格式化要显示的信息. br/>
DateTimePicker.CustomFormat [
A DateTimePicker class, you have the ability to custom format what informations you what to display.

DateTimePicker.CustomFormat[^]

If you known a start date and end date, use can you TimeSpan class to get total days.

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.


1.您需要在哪里显示日期?在DateTimePicker还是在文本框中?如果它是DateTimePicker,则为此使用了错误的控件.如果要在文本框中显示它,请执行以下操作:
1. Where do you need to display the days? In the DateTimePicker or in the textbox? If it is DateTimePicker, you are using the wrong control for this purpose. If you want to display it in the textbox, you the following:
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();


是的朋友,我的问题已经解决了.

我在第一个查询中有另一个问题.

当我选择2011年4月11日时显示354天,但我需要,它应该考虑

仅是2011年4月10日之前的日期,因此天数= 355

2nd.

在我的第二个问题中,我是否选择日期如2011年5月12日

文本框应该告诉剩余的天数= 20,因为应该花11个月的时间.

其他天数= 31
yes friend now my problem is over.

i have another question in 1st query.

when i choose 11-apr-2011 it shows 354 days.but i need, it should consider

only be-forth date that is 10-apr-2011 so days = 355

2nd.

in my 2nd question if i am selecting the date like 12-may-2011 the

textbox should tells the remaining days= 20 because 11-may should take.

else days = 31


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

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