TimePicker

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.

expand codeexpand code
import { TimePicker } from 'antd';
import moment from 'moment';

function onChange(time, timeString) {
  console.log(time, timeString);
}

ReactDOM.render(
  <TimePicker onChange={onChange} defaultOpenValue={moment('00:00:00', 'HH:mm:ss')} />,
  mountNode,
);

The input box comes in three sizes. large is used in the form, while the medium size is the default.

expand codeexpand code
import { TimePicker } from 'antd';
import moment from 'moment';

ReactDOM.render(
  <>
    <TimePicker defaultValue={moment('12:08:23', 'HH:mm:ss')} size="large" />
    <TimePicker defaultValue={moment('12:08:23', 'HH:mm:ss')} />
    <TimePicker defaultValue={moment('12:08:23', 'HH:mm:ss')} size="small" />
  </>,
  mountNode,
);

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

expand codeexpand code
import { TimePicker } from 'antd';
import moment from 'moment';

const format = 'HH:mm';

ReactDOM.render(<TimePicker defaultValue={moment('12:08', format)} format={format} />, mountNode);

Render addon contents to time picker panel's bottom.

expand codeexpand code
import { TimePicker, Button } from 'antd';

class TimePickerAddonDemo extends React.Component {
  state = { open: false };

  handleOpenChange = open => {
    this.setState({ open });
  };

  handleClose = () => this.setState({ open: false });

  render() {
    return (
      <TimePicker
        open={this.state.open}
        onOpenChange={this.handleOpenChange}
        renderExtraFooter={() => (
          <Button size="small" type="primary" onClick={this.handleClose}>
            OK
          </Button>
        )}
      />
    );
  }
}

ReactDOM.render(<TimePickerAddonDemo />, mountNode);

Use time range picker with TimePicker.RangePicker.

expand codeexpand code
import { TimePicker } from 'antd';

ReactDOM.render(<TimePicker.RangePicker />, mountNode);

value and onChange should be used together,

expand codeexpand code
import React, { useState } from 'react';
import { TimePicker } from 'antd';

const Demo = () => {
  const [value, setValue] = useState(null);

  const onChange = time => {
    setValue(time);
  };

  return <TimePicker value={value} onChange={onChange} />;
};

ReactDOM.render(<Demo />, mountNode);

A disabled state of the TimePicker.

expand codeexpand code
import { TimePicker } from 'antd';
import moment from 'moment';

ReactDOM.render(<TimePicker defaultValue={moment('12:08:23', 'HH:mm:ss')} disabled />, mountNode);

Show stepped options by hourStep minuteStep secondStep.

expand codeexpand code
import { TimePicker } from 'antd';

ReactDOM.render(<TimePicker minuteStep={15} secondStep={10} />, mountNode);

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

expand codeexpand code
import { TimePicker } from 'antd';

function onChange(time, timeString) {
  console.log(time, timeString);
}

ReactDOM.render(
  <>
    <TimePicker use12Hours onChange={onChange} />
    <TimePicker use12Hours format="h:mm:ss A" onChange={onChange} style={{ width: 140 }} />
    <TimePicker use12Hours format="h:mm a" onChange={onChange} />
  </>,
  mountNode,
);

Bordered-less style component.

expand codeexpand code
import { TimePicker } from 'antd';

const { RangePicker } = TimePicker;

ReactDOM.render(
  <>
    <TimePicker bordered={false} />
    <RangePicker bordered={false} />
  </>,
  mountNode,
);

API#


import moment from 'moment';

<TimePicker defaultValue={moment('13:30:56', 'HH:mm:ss')} />;
PropertyDescriptionTypeDefaultVersion
allowClearWhether allow clearing textbooleantrue
autoFocusIf get focus when component mountedbooleanfalse
borderedWhether has border stylebooleantrue
classNameThe className of pickerstring-
clearIconThe custom clear iconReactNode-
clearTextThe clear tooltip of iconstringclear
defaultValueTo set default timemoment-
disabledDetermine whether the TimePicker is disabledbooleanfalse
disabledHoursTo specify the hours that cannot be selectedfunction()-
disabledMinutesTo specify the minutes that cannot be selectedfunction(selectedHour)-
disabledSecondsTo specify the seconds that cannot be selectedfunction(selectedHour, selectedMinute)-
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
openWhether to popup panelbooleanfalse
placeholderDisplay when there's no valuestring | [string, string]Select a time
popupClassNameThe className of panelstring-
popupStyleThe style of panelCSSProperties-
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
suffixIconThe custom suffix iconReactNode-
use12HoursDisplay as 12 hours format, with default format h:mm:ss abooleanfalse
valueTo set timemoment-
onChangeA callback function, can be executed when the selected time is changingfunction(time: moment, timeString: string): void-
onOpenChangeA callback function which will be called while panel opening/closing(open: boolean) => void-
onSelectA callback function, executes when a value is selectedfunction(time: moment): void-

Methods#

NameDescriptionVersion
blur()Remove focus
focus()Get focus

RangePicker#

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

PropertyDescriptionTypeDefaultVersion
orderOrder start and end timebooleantrue4.1.0

FAQ#