# TimePicker
A styled time selector with separate dropdowns for hours and minutes (and optionally AM/PM). The selected time is always stored in a hidden input as `HH:MM` in 24-hour format, regardless of whether you show the 12-hour display mode.
---
## Quick example
```csharp
new TimePicker(name: "startTime", label: "Start time")
```
---
## All the options
```csharp
public TimePicker(
string name,
string? selected = null,
string label = "",
string description = "",
bool use12h = false)
```
| Parameter | What it does |
|---|---|
| `name` | Form field name. The hidden input gets this name and always holds a `HH:MM` value. The visible selects get `{name}-h`, `{name}-m`, `{name}-ampm`. |
| `selected` | Pre-selected time as `"HH:MM"` in 24-hour format. Defaults to the current time. |
| `label` | Visible text label above the picker. |
| `description` | Small hint text below the picker. |
| `use12h` | Show 12-hour mode with an AM/PM dropdown. The hidden input still stores 24h format. |
---
## Real-world examples
### Appointment booking with start and end times
```html
```
```csharp
// ScheduleForm.htmx.cs
_startTime = new TimePicker(name: "startTime", label: "Start", selected: "09:00");
_endTime = new TimePicker(name: "endTime", label: "End", selected: "17:00");
```
Reading on the server:
```csharp
public record Command(
[property: FromForm] string StartTime, // "HH:MM"
[property: FromForm] string EndTime
);
var start = TimeOnly.ParseExact(command.StartTime, "HH:mm");
var end = TimeOnly.ParseExact(command.EndTime, "HH:mm");
```
### 12-hour display mode with a pre-selected time
```csharp
new TimePicker(
name: "alarmTime",
selected: "07:30",
label: "Alarm time",
use12h: true)
```
The user sees `7:30 AM` in the dropdowns, but `07:30` is what gets submitted.
---
## How it works
TimePicker renders three `