DateTimePicker control, how to set time?
How to set time in a DateTimePicker control where i have already changed the display format = Time
I want to make the DateTimePicker to display time that i set.
e.g. set it to 5:30 PM
I try but fail using:
DateTimePicker1.Value = New DateTime(0, 0, 0, 5, 30开发者_高级运维, 0) 'fail at runtime
any idea, thanks
Try setting the date portion of the new DateTime to the current date:
DateTimePicker1.Value = new DateTime( DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 5, 30, 0 )
Then, when you want to read the value just take the time portion of the DateTime. The date portion has to be set to some value but since you are only displaying the time it doesn't really matter what it is.
This is because your year, month and day are all zero, which represent an impossible date. Try using 1's if you don't care about the actual date, or better, use the current date. Also be sure the control allows (via minimum and maximum) whatever value you set.
I hope following code snippets works for you!
dtPickerDesde.Value = new DateTime(dtPickerDesde.Value.Year, dtPickerDesde.Value.Month, dtPickerDesde.Value.Day, 0,0, 0);
dtPickerHasta.Value = new DateTime(dtPickerHasta.Value.Year, dtPickerHasta.Value.Month, dtPickerHasta.Value.Day, 23, 59, 59);
miRemision.Obtener(ref dtReporte, dtPickerDesde.Value, dtPickerHasta.Value);
dataGridView1.DataSource = dtReporte;
精彩评论