根据C#中的月份号获取第一个日期 [英] Get First Date based on Month Number in C#
本文介绍了根据C#中的月份号获取第一个日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获得每月的第一个日期
例如
如果我从组合框中选择4,它应该在文本框中显示2012/04/01
提前thx..
I want to get First Date of Month
For example
if i select 4 from combobox it should show 2012/04/01 in textbox
thx in advance..
推荐答案
如果comboBox1持有月份的字符串值(1,2,3,4,5,6,7,8,9 ,10,11,12):
If the comboBox1 holds the string value for the month (1,2,3,4,5,6,7,8,9,10,11,12):
DateTime date = new DateTime(DateTime.Now.Year, Convert.ToInt32(comboBox1.Text), 1);
textBox1.Text = date.ToString("yyyy.MM.dd");
只需正确构造DateTime对象(iSel
是组合框选择):
Just construct properly your DateTime object (iSel
is the combo box selection):
DateTime dt = new DateTime(DateTime.Now, iSel, 1);
这篇关于根据C#中的月份号获取第一个日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文