2017-06-17 79 views
0
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()); 

回答

0

如果我理解正确的话,它应该是这样简单:

var d = dateTimePicker1.Value; 

var newD = new DateTime(d.Year, d.Month, d.Day); 
+0

WOW。谢啦。理解我100%。有效! –

+0

看这个人! :D sticked –

+0

'Value'已经是一个DateTime,如果目标是只有一天(没有几小时),那么'var dateOnly = dateTimePicker1.Value.Date;'应该可能足够 – pinkfloydx33

0

DateTimePicker.Value物业已经是一个DateTime。刚才提到它:

DateTime d = dateTimePicker1.Value; 

如果你只在日期感兴趣,并希望忽略的时候,使用DateTime.Date属性:

DateTime d = dateTimePicker1.Value.Date;