Pankaj
Pankaj

Reputation: 2754

How to Select time in Date Time picker

I am using a DateTimePicker in Winforms, but it is showing only Dates to select from, not the time, How can I make the control to display like the shown in this image, so that user can select the time too.

enter image description here

I tried to add

dateTimePicker1.Format = DateTimePickerFormat.Time;
dateTimePicker1.CustomFormat = "MM dd yyyy hh mm ss";

but then it shows time in the Control itself, it doesn't shows the clock as displayed in the image.

Upvotes: 2

Views: 31828

Answers (2)

King King
King King

Reputation: 63387

You can set the CustomFormat for your DateTimePicker:

dateTimePicker1.CustomFormat = "MM/dd/yyyy hh:mm:ss tt";
dateTimePicker1.Format = DateTimePickerFormat.Custom;

NOTE: the code above will allow user to modify all the elements: dates and time. I think that's what you want. If you want to show the Clock, it's a lot to do more. There are some simple Clock control already built for you.

You can search for more with the keyword Clock control, especially in codeproject.com (there are tons of controls), here is just 1:

http://www.codeproject.com/Articles/10627/Yet-Another-Analog-Clock

Upvotes: 4

Vaibs_Cool
Vaibs_Cool

Reputation: 6160

timePicker = new DateTimePicker();
timePicker.Format = DateTimePickerFormat.Time;
timePicker.ShowUpDown = true;

Reference:-http://msdn.microsoft.com/en-us/library/ms229631.aspx

Upvotes: 4

Related Questions