简体   繁体   中英

how to reset the time of datetimepicker in C#

I want to reset the time of a date time picker to 00:00 manually. When i select the date from it i get the time of the instance i select the time is there any way i can reset it to given time?

How about this:

picker.Value = picker.Value.Date;

EDIT: To specify a particular time, you'd use something like:

TimeSpan time = new TimeSpan(3, 30, 0); // 3 hours and 30 minutes
picker.Value = picker.Value.Date + time;

Reset time to 00:00:00

dateTimePicker.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);

Before reset:

2009-08-15 20:27:42

After reset

2009-08-15 00:00:00

您可以转到设计器并将DateTimePicker控件的Value属性设置为00:00 - 它将在设计器中消失,但值将为00:00。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM