TimePicker
To select/input a time.
When To Use
By clicking the input box, you can select a time from a popup panel.
Examples
-
Basic ·
basic -
Under Control ·
value -
Three Sizes ·
size -
Need Confirm ·
need-confirm -
disabled ·
disabled -
Hour and minute ·
hide-column -
interval option ·
interval-options -
Addon ·
addon -
12 hours ·
12hours -
Change on scroll ·
change-on-scroll -
Time Range Picker ·
range-picker -
Variants ·
variant -
Status ·
status -
Prefix and Suffix ·
suffix -
Custom semantic dom styling ·
style-class
API
Common props ref:Common props
import dayjs from 'dayjs';
import customParseFormat from 'dayjs/plugin/customParseFormat'
dayjs.extend(customParseFormat)
<TimePicker defaultValue={dayjs('13:30:56', 'HH:mm:ss')} />;
| Property | Description | Type | Default | Version | Global Config |
|---|---|---|---|---|---|
| allowClear | Customize clear icon | boolean | { clearIcon?: ReactNode } | true | 5.8.0: Support object type | 6.4.0 |
Called from time picker panel to render an addon to its bottom, please use renderExtraFooter instead | () => ReactNode | - | - | × | |
| cellRender | Custom rendering function for picker cells | (current: number, info: { originNode: React.ReactElement, today: dayjs, range?: 'start' | 'end', subType: 'hour' | 'minute' | 'second' | 'meridiem' }) => React.ReactNode | - | 5.4.0 | × |
| changeOnScroll | Trigger selection when scroll the column | boolean | false | 5.14.0 | × |
| classNames | Customize class for each semantic structure inside the component. Supports object or function. | Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string> | - | 5.25.0 | |
| defaultValue | To set default time | dayjs | - | × | |
| disabled | Determine whether the TimePicker is disabled | boolean | false | × | |
| disabledTime | To specify the time that cannot be selected | DisabledTime | - | 4.19.0 | × |
| format | To set the time format | string | HH:mm:ss | × | |
| getPopupContainer | To set the container of the floating layer, while the default is to create a div element in body | function(trigger) | - | × | |
| hideDisabledOptions | Whether hide the options that can not be selected | boolean | false | × | |
| hourStep | Interval between hours in picker | number | 1 | × | |
| inputReadOnly | Set the readonly attribute of the input tag (avoids virtual keyboard on touch devices) | boolean | false | × | |
| minuteStep | Interval between minutes in picker | number | 1 | × | |
| needConfirm | Need click confirm button to trigger value change | boolean | - | 5.14.0 | × |
| open | Whether to popup panel | boolean | false | × | |
| placeholder | Display when there's no value | string | [string, string] | Select a time | × | |
| placement | The position where the selection box pops up | bottomLeft bottomRight topLeft topRight | bottomLeft | × | |
The className of panel, please use classNames.popup instead | string | - | × | ||
The style of panel, please use styles.popup instead | CSSProperties | - | × | ||
| prefix | The custom prefix | ReactNode | - | 5.22.0 | × |
| previewValue | When the user selects the time hover option, the value of the input field undergoes a temporary change | false | hover | hover | 6.0.0 | × |
| renderExtraFooter | Called from time picker panel to render some addon to its bottom | () => ReactNode | - | × | |
| secondStep | Interval between seconds in picker | number | 1 | × | |
| showNow | Whether to show Now button on panel | boolean | - | 4.4.0 | × |
| size | To determine the size of the input box, the height of large and small, are 40px and 24px respectively, while default size is 32px | large | medium | small | - | × | |
| status | Set validation status | 'error' | 'warning' | 'success' | 'validating' | - | 4.19.0 | × |
| styles | Customize inline style for each semantic structure inside the component. Supports object or function. | Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties> | - | 5.25.0 | |
| suffixIcon | The custom suffix icon | ReactNode | - | 6.3.0 | |
| use12Hours | Display as 12 hours format, with default format h:mm:ss a | boolean | false | × | |
| value | To set time | dayjs | - | × | |
| variant | Variants of picker | outlined | borderless | filled | underlined | outlined | 5.13.0 | underlined: 5.24.0 | 5.19.0 |
| onCalendarChange | Callback function, can be executed when the start time or the end time of the range is changing. info argument is added in 4.4.0 | function(dates: [dayjs, dayjs], dateStrings: [string, string], info: { range:start|end }) | - | × | |
| onChange | A callback function, can be executed when the selected time is changing | function(time: dayjs, timeString: string): void | - | × | |
| onClear | Callback when click the clear button | () => void | - | 6.5.0 | × |
| onOpenChange | A callback function which will be called while panel opening/closing | (open: boolean) => void | - | × |
DisabledTime
type DisabledTime = (now: Dayjs) => {
disabledHours?: () => number[];
disabledMinutes?: (selectedHour: number) => number[];
disabledSeconds?: (selectedHour: number, selectedMinute: number) => number[];
disabledMilliseconds?: (
selectedHour: number,
selectedMinute: number,
selectedSecond: number,
) => number[];
};
Note: disabledMilliseconds is added in 5.14.0.
Methods
| Name | Description | Version |
|---|---|---|
| blur() | Remove focus | |
| focus() | Get focus |
RangePicker
Same props from RangePicker of DatePicker. And includes additional props:
| Property | Description | Type | Default | Version |
|---|---|---|---|---|
| disabledTime | To specify the time that cannot be selected | RangeDisabledTime | - | 4.19.0 |
| order | Order start and end time | boolean | true | 4.1.0 |
RangeDisabledTime
type RangeDisabledTime = (
now: Dayjs,
type = 'start' | 'end',
) => {
disabledHours?: () => number[];
disabledMinutes?: (selectedHour: number) => number[];
disabledSeconds?: (selectedHour: number, selectedMinute: number) => number[];
};
Semantic DOM
| Semantic node | Native description | Version |
|---|---|---|
root | Root element with relative positioning, inline-flex layout, padding, border-radius, transition animations and other basic styles for date picker container | — |
prefix | Prefix element with flex layout and margin styles for prefix content layout | — |
input | Input element with relative positioning, width, color, font, line-height, transition animations and other core interactive styles for input field | — |
suffix | Suffix element with flex layout, color, line-height, pointer events, transition animations and other styles for suffix content | — |
popup.root | Popup element | — |
popup.container | Container element, set background color, padding, border radius, shadow, border and content display styles | — |
popup.content | Popup content element with width, border, cell and other content display styles for date table | — |
popup.item | Popup item element with size, background, border-radius, hover state, selected state and other interactive styles for date cells | — |
popup.footer | Popup footer element with layout styles for bottom operation area including confirm/cancel buttons and shortcuts | — |
Semantic description source: vendor/components/date-picker/demo/_semantic.tsx
Design Token
Types, inheritance and declarations retain the pinned native source. Defaults are computed by the native theme and may be overridden by ConfigProvider; this table does not invent static defaults.
| Token | Type | Native description |
|---|---|---|
presetsWidth | number | Width of preset area |
presetsMaxWidth | number | Max width of preset area |
zIndexPopup | number | z-index of popup |
Declaration source: vendor/components/date-picker/style/token.ts
import { FastColor } from '@ant-design/fast-color';
import type { SharedComponentToken, SharedInputToken } from '../../input/style/token';
import { initComponentToken } from '../../input/style/token';
import type { MultipleSelectorToken, SelectorToken } from '../../select/style/token';
import type { ArrowToken } from '../../style/roundedArrow';
import { getArrowToken } from '../../style/roundedArrow';
import type {
FullToken,
GetDefaultToken,
GlobalToken,
TokenWithCommonCls,
} from '../../theme/internal';
export interface PanelComponentToken extends MultipleSelectorToken {
/**
* @desc 单元格悬浮态背景色
* @descEN Background color of cell hover state
*/
cellHoverBg: string;
/**
* @desc 选取范围内的单元格背景色
* @descEN Background color of cell in range
*/
cellActiveWithRangeBg: string;
/**
* @desc 选取范围内的单元格悬浮态背景色
* @descEN Background color of hovered cell in range
*/
cellHoverWithRangeBg: string;
/**
* @desc 单元格禁用态背景色
* @descEN Background color of disabled cell
*/
cellBgDisabled: string;
/**
* @desc 选取范围时单元格边框色
* @descEN Border color of cell in range when picking
*/
cellRangeBorderColor: string;
/**
* @desc 时间列宽度
* @descEN Width of time column
*/
timeColumnWidth: number;
/**
* @desc 时间列高度
* @descEN Height of time column
*/
timeColumnHeight: number;
/**
* @desc 时间单元格高度
* @descEN Height of time cell
*/
timeCellHeight: number;
/**
* @desc 单元格高度
* @descEN Height of cell
*/
cellHeight: number;
/**
* @desc 单元格宽度
* @descEN Width of cell
*/
cellWidth: number;
/**
* @desc 单元格文本高度
* @descEN Height of cell text
*/
textHeight: number;
/**
* @desc 十年/年/季/月/周单元格高度
* @descEN Height of decade/year/quarter/month/week cell
*/
withoutTimeCellHeight: number;
}
export interface ComponentToken
extends Exclude<SharedComponentToken, 'addonBg'>,
PanelComponentToken,
ArrowToken {
/**
* @desc 预设区域宽度
* @descEN Width of preset area
*/
presetsWidth: number;
/**
* @desc 预设区域最大宽度
* @descEN Max width of preset area
*/
presetsMaxWidth: number;
/**
* @desc 弹窗 z-index
* @descEN z-index of popup
*/
zIndexPopup: number;
}
export type PickerPanelToken = {
pickerCellCls: string;
pickerCellInnerCls: string;
pickerDatePanelPaddingHorizontal: number | string;
pickerYearMonthCellWidth: number | string;
pickerCellPaddingVertical: number | string;
pickerQuarterPanelContentHeight: number | string;
pickerCellBorderGap: number;
pickerControlIconSize: number;
pickerControlIconMargin: number;
pickerControlIconBorderWidth: number;
};
export interface PickerToken
extends FullToken<'DatePicker'>,
PickerPanelToken,
SharedInputToken,
SelectorToken {
/** @private Used for internal calculation */
INTERNAL_FIXED_ITEM_MARGIN: number;
}
export type SharedPickerToken = TokenWithCommonCls<GlobalToken> &
PickerPanelToken &
PanelComponentToken;
FAQ
Shared native props
Tips: The following generic properties apply to most antd components; those not supported are described separately.
| Property | Description | Type | Default |
|---|---|---|---|
| style | The additional style | CSSProperties | - |
| className | The additional css class | string | - |
| rootClassName | ClassName on the root element | string | - |
| autoFocus | Auto focus when component mounted, only effective for focusable elements like forms, links, etc. | boolean | false |
Install and reproduce an example
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23
Use ConfigProvider and native App; configure dayjs locale separately. Each example lists its complete source files and additional pinned dependencies in View code. Example names select demos, not universal component props. See the resource setup guide for theme, locale and SSR.
Native type references
The source viewer includes unchanged native implementations and the following source declarations. Inherited types remain in their native packages. English source comments are preserved as code reference.
vendor/components/time-picker/index.tsx
Source and license
https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd
Original bilingual prose and executable examples are retained. Website-only embeds and token tables are expanded locally. Ant Design is MIT; separately listed dependency notices also apply. Upload previews block outbound requests and do not provide a backend.