插入DateTimePicker的值转换成funtion
问题描述:
private void btntest_Click(object sender, EventArgs e)
{
DateTime d = new DateTime(2016,2,13);
LunarDate ld1 = LunarYearTools.SolarToLunar(d);
lblamlich.Text = (ld1.ToString());
}
注
DateTime d = new DateTime(Int year,Int month,Int day)
插入DateTimePicker的值转换成funtion
如何插入DateTimePicker的价值为new DateTime(2016,2,13)
??? 我试图用铸造日期时间到Int
,但没有奏效:
string a = dateTimePicker1.Value.ToString();
int b = (int)(a);
DateTime d = new DateTime(b);
LunarDate ld1 = LunarYearTools.SolarToLunar(d);
lblamlich.Text = (ld1.ToString());
答
如果我理解正确的话,它应该是这样简单:
var d = dateTimePicker1.Value;
var newD = new DateTime(d.Year, d.Month, d.Day);
答
的DateTimePicker.Value
物业已经是一个DateTime
。刚才提到它:
DateTime d = dateTimePicker1.Value;
如果你只在日期感兴趣,并希望忽略的时候,使用DateTime.Date
属性:
DateTime d = dateTimePicker1.Value.Date;
WOW。谢啦。理解我100%。有效! –
看这个人! :D sticked –
'Value'已经是一个DateTime,如果目标是只有一天(没有几小时),那么'var dateOnly = dateTimePicker1.Value.Date;'应该可能足够 – pinkfloydx33