combining DatePicker and TimePicker
typically when I have a timepicker and a datePicker on a winform I combine the two into one date object by using the new DateTime (y,m,d,h,mi,s) constructor. this seems kind of long winded, and I was wondering what approach others are using if faced with this situation.
DateTime date =
new DateTime(DatePicker.Value.Year, DatePicker.Value.Month, DatePicker.Value.Day,
TimePicker.Value.Hour, TimePicker.Value.Minute, TimePicker.Value.Second);
looks like it was just a simple.
DateTime date = DatePicker.Va开发者_开发百科lue.Date.Add(TimePicker.Value.TimeOfDay);
I didn't realize
hope you have used DateTimePicker for selecting Date and Time. in this case you can combine date and time like
DateTime date = DatePicker.Value.Date + TimePicker.Value.TimeOfDay;
Have you tried DateTimePicker ?
I have found the following code helpful:-
int rex01= t21.Date.Value.Year;
int rex02 = t21.Date.Value.Month;
int rex03 = t21.Date.Value.Day;
int rex04 = t22.Time.Hours;
int rex05 = t22.Time.Minutes;
int rex06 = t22.Time.Seconds;
DateTime T02 = new DateTime(rex01, rex02, rex03, rex04, rex05, rex06);
Please note t21 is a DatePicker and t22 is a TimePicker.
Currently used with respect to SQLite and UWP.
精彩评论