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的值插入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());
答案 0 :(得分:0)
如果我理解正确,那就应该这么简单:
var d = dateTimePicker1.Value;
var newD = new DateTime(d.Year, d.Month, d.Day);
答案 1 :(得分:0)
DateTimePicker.Value
属性已经是DateTime
。请参考它:
DateTime d = dateTimePicker1.Value;
如果您只对日期感兴趣并希望忽略时间,请使用DateTime.Date
属性:
DateTime d = dateTimePicker1.Value.Date;