将 DatetimePicker 值插入函数
Insert DatetimePicker's value into a 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());
}
Note DateTime d = new DateTime(Int year,Int month,Int day)
如何将日期时间选择器的值插入 new DateTime(2016,2,13)
???
我尝试将 datetime 转换为 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;
private void btntest_Click(object sender, EventArgs e)
{
DateTime d = new DateTime(2016,2,13);
LunarDate ld1 = LunarYearTools.SolarToLunar(d);
lblamlich.Text = (ld1.ToString());
}
Note
DateTime d = new DateTime(Int year,Int month,Int day)
如何将日期时间选择器的值插入 new DateTime(2016,2,13)
???
我尝试将 datetime 转换为 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;