如何选择本月的第一个日期作为默认值 [英] how to select the 1st date of present month as default

查看:79
本文介绍了如何选择本月的第一个日期作为默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi ..
我有两个想要的日期字段
在该
中打印日期 在一个datefield日期1/当前月/2011中
并在第二个日期字段presentDate/presentMonth/2011 ..

怎么做...
帮帮我..

hi..
i''ve two datefield i want to
print the date in that
in one datefield date 1/present month/2011
and in second datefield presentDate/presentMonth/2011..

how to do this...
help me..

推荐答案



尝试以下代码....

Hi,

Try the following Code....

DateTime dt1 = DateTime.Now.Date;
DateTime dt2 = dt1.Date.AddDays(-1* (dt1.Day - 1));



现在,您在 dt1 中获得当前日期,并在 dt2
中获得该月的第一个日期.
在日期控件中设置这些值.

干杯:)



Now you get Current Date in dt1 and also get first date of that month in dt2

Set those values in your date control.

Cheers :)


您可以像这样完成它:

You can get it done like this:

// format string to format the date like you need it
String formatString = "dd/MM/yyyy";
DateTime now = DateTime.Now;
DateTime date = new DateTime(now.Year, now.Month, 1); // create a date with current year and month and day 1
textBox1.Text = date.ToString(formatString);
textBox2.Text = now.ToString(formatString);



那应该为您做!

另请参阅此页面以了解有关DateTime格式字符串的所有信息: microsoft.com/en-us/library/system.globalization.datetimeformatinfo.aspx [



That should do it for you!

Please also refer to this page to learn all about DateTime format strings:http://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.aspx[^]

Best Regards,
Manfred


这篇关于如何选择本月的第一个日期作为默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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