I confuse with datatimepickers and datetimes. Need some help
Need 开发者_Go百科some your help.
I have two datetimepickers on my form: dt1 and dt2.
dt1 is for picking a date.
dt2 is for picking a time.
How can I get a DateTime dt where Date component is from dt1 and time component is from dt2 ?
C#, .net 2.0
You can read the Date component from the value of dt1
and the time component from the value of dt2
and combine them with the Add
method, like this:
DateTime theDate = dt1.Value.Date;
TimeSpan theTime = dt2.Value.TimeOfDay;
DateTime dt = theDate.Add(theTime);
// dt now contains date from dt1 and time from dt2
精彩评论