|
| 1 | +--- |
| 2 | +title: Overview |
| 3 | +page_title: Time Picker for Blazor Overview |
| 4 | +description: Overview of the Time Picker for Blazor |
| 5 | +slug: components/timepicker/overview |
| 6 | +tags: telerik,blazor,time,picker,timepicker,overview |
| 7 | +published: True |
| 8 | +position: 0 |
| 9 | +--- |
| 10 | + |
| 11 | +# Time Picker Overview |
| 12 | + |
| 13 | +The Time Picker component allows the user to choose a time from a visual list in a dropdown, or to type it into a [date input]({%slug components/dateinput/overview%}) that can accept only DateTime values. You can control the format shown in the input and respond to [events]({%slug components/timepicker/events %}). |
| 14 | + |
| 15 | +To use a Telerik Time Picker for Blazor, add the `TelerikTimePicker` tag. |
| 16 | + |
| 17 | +>caption Basic time picker with custom format, min and max |
| 18 | +
|
| 19 | +````CSHTML |
| 20 | +@using Telerik.Blazor.Components.TimePicker |
| 21 | +
|
| 22 | +<TelerikTimePicker Min="@Min" Max="@Max" Format="hh:mm:ss tt" @bind-Value="@selectedTime"></TelerikTimePicker> |
| 23 | +
|
| 24 | +Selected time: @selectedTime?.ToLongTimeString() |
| 25 | +
|
| 26 | +@code { |
| 27 | + private DateTime? selectedTime = DateTime.Now; |
| 28 | +
|
| 29 | + // only the time portions are used |
| 30 | + public DateTime Min = new DateTime(1900, 1, 1, 8, 15, 0); |
| 31 | + public DateTime Max = new DateTime(1900, 1, 1, 19, 30, 45); |
| 32 | +} |
| 33 | +```` |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +>caption Component namespace and reference |
| 38 | +
|
| 39 | +````CSHTML |
| 40 | +@using Telerik.Blazor.Components.TimePicker |
| 41 | +
|
| 42 | +<TelerikTimePicker @bind-Value="@theTimePickerValue"></TelerikTimePicker> |
| 43 | +@theTimePickerValue |
| 44 | +
|
| 45 | +@code { |
| 46 | + DateTime? theTimePickerValue { get; set; } |
| 47 | + |
| 48 | + // the time picker is a generic component and its type comes from the value field type |
| 49 | + Telerik.Blazor.Components.TimePicker.TelerikTimePicker<DateTime?> theTimePicker; |
| 50 | +} |
| 51 | +```` |
| 52 | + |
| 53 | +The Time Picker component exposes the following features: |
| 54 | + |
| 55 | +* `Enabled` - Specifies whether typing in the input is allowed. |
| 56 | +* `Height` - Defines the height of the TimePicker. Defaults to `28px`. See the [Dimensions]({%slug common-features/dimensions%}) article. |
| 57 | +* `Format` - Specifies the format of the DateInput of the TimePicker. Defaults to `HH:mm` (24 hour time format). Read more in the [Supported Formats]({%slug components/dateinput/supported-formats%}) article. Note that format specifiers for non-time portions will only be editable in the input and will not have a representation in the time picker dropdown. |
| 58 | +* `Min` - The earliest time that the user can select. |
| 59 | +* `Max` - The latest time that the user can select. |
| 60 | +* `Value` - The current value of the input. Can be used for binding. |
| 61 | +* `Width` - Defines the width of the TimePicker. |
| 62 | +* Validation - see the [Input Validation]({%slug common-features/input-validation%}) article. |
| 63 | + |
| 64 | +The `Min` and `Max` properties require a `DateTime` object, but will only use the time portion from it. Thus, the date itself is not important. The hours, minutes, seconds and AM/PM portions control the range of the tumblers in the time picker dropdown. They do not impose validation/limitations on the input editing. |
| 65 | + |
| 66 | +When using the dropdown to edit dates, you must click the "Set" button to commit the date. Clicking "Cancel", or outside of the dropdown without clicking "Set", will revert the time to the original value. You can also commit a date by clicking the "NOW" button which will choose the current time. |
| 67 | + |
| 68 | +The time format specifiers in the `Format` control the tumblers available in the dropdown. For example, the `HH` specifier will result in a hour selector in a 24 hour format. If you also add the `tt` specifier, you will also get the AM/PM tumbler, but the 24 hour format will still be used. This means that you can also add several tumblers for the same time portion if the format string repeats them. |
| 69 | + |
| 70 | +The Time Picker component supports `DateTime`, `DateTime?`, `DateTimeOffset` and `DateTimeOffset?` types. |
| 71 | + |
| 72 | + |
| 73 | +## See Also |
| 74 | + |
| 75 | + * [Live Demo: Time Picker](https://demos.telerik.com/blazor-ui/timepicker/index) |
| 76 | + * [Input Validation]({%slug common-features/input-validation%}) |
| 77 | + * [Supported Input Date Formats]({%slug components/dateinput/supported-formats%}) |
0 commit comments