TimePicker

To select/input a time.
Importimport{ TimePicker }from"antd";

When To Use

By clicking the input box, you can select a time from a popup panel.

Examples

Click TimePicker, and then we could select or input a time in panel.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

The input box comes in three sizes: large, middle and small. Large is used in the form, while the medium size is the default.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

A disabled state of the TimePicker.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

Show stepped options by hourStep minuteStep secondStep.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

TimePicker of 12 hours format, with default format h:mm:ss a.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

Use time range picker with TimePicker.RangePicker.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

Add status to TimePicker with status, which could be error or warning.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

value and onChange should be used together,

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

TimePicker will automatically determine whether to show a confirm button according to the picker property. You can also set the needConfirm property to determine whether to show a confirm button. When needConfirm is set, the user must click the confirm button to complete the selection. Otherwise, the selection will be submitted when the picker loses focus or select a time.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
5.14.0

While part of format is omitted, the corresponding column in panel will disappear, too.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

Render addon contents to time picker panel's bottom.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

Use changeOnScroll and needConfirm to change the value when scrolling.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
5.14.0

Bordered-less style component.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
5.13.0

Custom prefix and suffixIcon.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

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')} />;
PropertyDescriptionTypeDefaultVersion
allowClearCustomize clear iconboolean | { clearIcon?: ReactNode }true5.8.0: Support object type
autoFocusIf get focus when component mountedbooleanfalse
cellRenderCustom 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
changeOnScrollTrigger selection when scroll the columnbooleanfalse5.14.0
classNameThe className of pickerstring-
defaultValueTo set default timedayjs-
disabledDetermine whether the TimePicker is disabledbooleanfalse
disabledTimeTo specify the time that cannot be selectedDisabledTime-4.19.0
formatTo set the time formatstringHH:mm:ss
getPopupContainerTo set the container of the floating layer, while the default is to create a div element in bodyfunction(trigger)-
hideDisabledOptionsWhether hide the options that can not be selectedbooleanfalse
hourStepInterval between hours in pickernumber1
inputReadOnlySet the readonly attribute of the input tag (avoids virtual keyboard on touch devices)booleanfalse
minuteStepInterval between minutes in pickernumber1
needConfirmNeed click confirm button to trigger value changeboolean-5.14.0
openWhether to popup panelbooleanfalse
placeholderDisplay when there's no valuestring | [string, string]Select a time
placementThe position where the selection box pops upbottomLeft bottomRight topLeft topRightbottomLeft
popupClassNameThe className of panelstring-
popupStyleThe style of panelCSSProperties-
prefixThe custom prefixReactNode-5.22.0
renderExtraFooterCalled from time picker panel to render some addon to its bottom() => ReactNode-
secondStepInterval between seconds in pickernumber1
showNowWhether to show Now button on panelboolean-4.4.0
sizeTo determine the size of the input box, the height of large and small, are 40px and 24px respectively, while default size is 32pxlarge | middle | small-
statusSet validation status'error' | 'warning' | 'success' | 'validating'-4.19.0
suffixIconThe custom suffix iconReactNode-
use12HoursDisplay as 12 hours format, with default format h:mm:ss abooleanfalse
valueTo set timedayjs-
variantVariants of pickeroutlined | borderless | filledoutlined5.13.0
onCalendarChangeCallback function, can be executed when the start time or the end time of the range is changing. info argument is added in 4.4.0function(dates: [dayjs, dayjs], dateStrings: [string, string], info: { range:start|end })-
onChangeA callback function, can be executed when the selected time is changingfunction(time: dayjs, timeString: string): void-
onOpenChangeA 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

NameDescriptionVersion
blur()Remove focus
focus()Get focus

RangePicker

Same props from RangePicker of DatePicker. And includes additional props:

PropertyDescriptionTypeDefaultVersion
disabledTimeTo specify the time that cannot be selectedRangeDisabledTime-4.19.0
orderOrder start and end timebooleantrue4.1.0

RangeDisabledTime

type RangeDisabledTime = (
now: Dayjs,
type = 'start' | 'end',
) => {
disabledHours?: () => number[];
disabledMinutes?: (selectedHour: number) => number[];
disabledSeconds?: (selectedHour: number, selectedMinute: number) => number[];
};

Design Token

Component TokenHow to use?

Token NameDescriptionTypeDefault Value
activeBgBackground color when the input box is activatedstring#ffffff
activeBorderColorActive border colorstring#1677ff
activeShadowBox-shadow when activestring0 0 0 2px rgba(5,145,255,0.1)
addonBgBackground color of addonstringrgba(0,0,0,0.02)
cellActiveWithRangeBgBackground color of cell in rangestring#e6f4ff
cellBgDisabledBackground color of disabled cellstringrgba(0,0,0,0.04)
cellHeightHeight of cellnumber24
cellHoverBgBackground color of cell hover statestringrgba(0,0,0,0.04)
cellHoverWithRangeBgBackground color of hovered cell in rangestring#cbe0fd
cellRangeBorderColorBorder color of cell in range when pickingstring#82b4f9
cellWidthWidth of cellnumber36
errorActiveShadowBox-shadow when active in error statusstring0 0 0 2px rgba(255,38,5,0.06)
hoverBgBackground color when the input box hoversstring#ffffff
hoverBorderColorHover border colorstring#4096ff
inputFontSizeFont sizenumber14
inputFontSizeLGFont size of largenumber16
inputFontSizeSMFont size of smallnumber14
multipleItemBgBackground color of multiple tagstringrgba(0,0,0,0.06)
multipleItemBorderColorBorder color of multiple tagstringtransparent
multipleItemBorderColorDisabledBorder color of multiple tag when disabledstringtransparent
multipleItemColorDisabledText color of multiple tag when disabledstringrgba(0,0,0,0.25)
multipleItemHeightHeight of multiple tagnumber24
multipleItemHeightLGHeight of multiple tag with large sizenumber32
multipleItemHeightSMHeight of multiple tag with small sizenumber16
multipleSelectorBgDisabledBackground color of multiple selector when disabledstringrgba(0,0,0,0.04)
paddingBlockVertical padding of inputnumber4
paddingBlockLGVertical padding of large inputnumber7
paddingBlockSMVertical padding of small inputnumber0
paddingInlineHorizontal padding of inputnumber11
paddingInlineLGHorizontal padding of large inputnumber11
paddingInlineSMHorizontal padding of small inputnumber7
presetsMaxWidthMax width of preset areanumber200
presetsWidthWidth of preset areanumber120
textHeightHeight of cell textnumber40
timeCellHeightHeight of time cellnumber28
timeColumnHeightHeight of time columnnumber224
timeColumnWidthWidth of time columnnumber56
warningActiveShadowBox-shadow when active in warning statusstring0 0 0 2px rgba(255,215,5,0.1)
withoutTimeCellHeightHeight of decade/year/quarter/month/week cellnumber66
zIndexPopupz-index of popupnumber1050

Global TokenHow to use?