Skip to content

TimePicker

A time picker component.

Basic Usage

Limit selectable time ranges via disabledHours, disabledMinutes, and disabledSeconds.

Two interaction modes are provided: by default, use the mouse wheel to select; with arrow-control, use the arrow buttons on the interface.

<template>
  <div flex>
    <div style="width: 220px; margin-right: 20px">
      <b-time-picker
        v-model="value1"
        :disabled-hours="disabledHours"
        :disabled-minutes="disabledMinutes"
        :disabled-seconds="disabledSeconds"
        placeholder="Any time point"
      ></b-time-picker>
    </div>
    <div style="width: 220px; margin-right: 20px">
      <b-time-picker
        v-model="value2"
        arrow-control
        :disabled-hours="disabledHours"
        :disabled-minutes="disabledMinutes"
        :disabled-seconds="disabledSeconds"
        placeholder="Any time point"
      ></b-time-picker>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const value1 = ref(new Date(2016, 9, 10, 18, 40))
const value2 = ref(new Date(2016, 9, 10, 18, 40))

const makeRange = (start, end) => {
  const result = []
  for (let i = start; i <= end; i++) {
    result.push(i)
  }
  return result
}

function disabledHours() {
  return makeRange(0, 16).concat(makeRange(19, 23))
}

function disabledMinutes(hour) {
  if (hour === 17) {
    return makeRange(0, 29)
  }
  if (hour === 18) {
    return makeRange(31, 59)
  }
}

function disabledSeconds(hour, minute) {
  if (hour === 18 && minute === 30) {
    return makeRange(1, 59)
  }
}
</script>

Time Range

Add is-range to enable time range selection. Also supports the arrow-control prop.

To
   
To
<template>
  <div flex>
    <b-time-picker
      v-model="value1"
      style="width: 340px"
      is-range
      range-separator="To"
      start-placeholder="Start Time"
      end-placeholder="End Time"
      placeholder="Select Time Range"
    ></b-time-picker>
    &nbsp; &nbsp;
    <b-time-picker
      v-model="value2"
      style="width: 340px"
      is-range
      arrow-control
      range-separator="To"
      start-placeholder="Start Time"
      end-placeholder="End Time"
      placeholder="Select Time Range"
    ></b-time-picker>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const value1 = ref([new Date(2016, 9, 10, 8, 40), new Date(2016, 9, 10, 9, 40)])
const value2 = ref([new Date(2016, 9, 10, 8, 40), new Date(2016, 9, 10, 9, 40)])
</script>

Disabled State and Disabled Time

Limit selectable time ranges via disabledHours, disabledMinutes, and disabledSeconds.

<template>
  <div flex>
    <div style="width: 220px; margin-right: 20px">
      <b-time-picker
        v-model="value1"
        :disabled-hours="disabledHours"
        :disabled-minutes="disabledMinutes"
        :disabled-seconds="disabledSeconds"
        placeholder="Any time point"
      ></b-time-picker>
    </div>
    <div style="width: 220px; margin-right: 20px">
      <b-time-picker disabled placeholder="Disabled"></b-time-picker>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const value1 = ref(new Date(2016, 9, 10, 18, 40))

const makeRange = (start, end) => {
  const result = []
  for (let i = start; i <= end; i++) {
    result.push(i)
  }
  return result
}

function disabledHours() {
  return makeRange(0, 16).concat(makeRange(19, 23))
}

function disabledMinutes(hour) {
  if (hour === 17) {
    return makeRange(0, 29)
  }
  if (hour === 18) {
    return makeRange(31, 59)
  }
}

function disabledSeconds(hour, minute) {
  if (hour === 18 && minute === 30) {
    return makeRange(1, 59)
  }
}
</script>

Time Format

Set the format prop to change the display format of the time.

Note: format only changes the display format, not the bound value.

~
<template>
  <div flex>
    <div style="width: 220px; margin-right: 20px">
      <b-time-picker
        v-model="value1"
        format="HH:mm:ss"
        placeholder="Any time"
      ></b-time-picker>
    </div>
    <div style="width: 220px; margin-right: 20px">
      <b-time-picker
        v-model="value2"
        is-range
        arrow-control
        format="HH:mm:ss"
        range-separator="~"
        start-placeholder="Start time"
        end-placeholder="End time"
        placeholder="Select time range"
      >
        >
      </b-time-picker>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const value1 = ref(new Date(2023, 9, 10, 18, 40))
const value2 = ref([new Date(2023, 4, 270, 18, 40), new Date(2023, 4, 30, 11, 40)])
</script>

Sizes

Different sizes can be configured.

<template>
  <div flex>
    <div style="width: 240px; margin-right: 20px">
      <b-time-picker v-model="value1" size="large"></b-time-picker>
    </div>
    <div style="width: 240px; margin-right: 20px">
      <b-time-picker v-model="value1"></b-time-picker>
    </div>
    <div style="width: 240px; margin-right: 20px">
      <b-time-picker v-model="value1" size="small"></b-time-picker>
    </div>
    <div style="width: 240px; margin-right: 20px">
      <b-time-picker v-model="value1" size="mini"></b-time-picker>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const value1 = ref(new Date(2016, 9, 10, 18, 40))
</script>

Props

ParameterDescriptionTypeOptionsDefault
value / v-modelBound valuedate (Date)
readonlyFully read-onlybooleanfalse
disabledDisabledbooleanfalse
editableText field is editablebooleantrue
clearableShow clear buttonbooleantrue
sizeInput sizestringmedium / small / mini
placeholderPlaceholder for non-range selectionstring
start-placeholderPlaceholder for start date in range selectionstring
end-placeholderPlaceholder for start date in range selectionstring
is-rangeIs a time range selectionbooleanfalse
arrow-controlUse arrow buttons for time selectionbooleanfalse
alignAlignmentstringleft / center / rightleft
popper-classCustom class name for TimePicker dropdownstring
range-separatorSeparator for range selectionstring-'-'
formatDisplay format in the inputstring-HH:mm:ss
default-valueOptional, default time displayed when the picker opensDate(TimePicker) / string(TimeSelect)Parseable by new Date()(TimePicker) / Options(TimeSelect)
nameNative attributestring
prefix-iconCustom prefix icon class namestringtime-circle
clear-iconCustom clear icon class namestringclose-circle-fill
disabledHoursDisable specific hour optionsfunction-
disabledMinutesDisable specific minute optionsfunction(selectedHour)-
disabledSecondsDisable specific second optionsfunction(selectedHour, selectedMinute)-

Events

Event NameDescriptionParameter
changeTriggers when the user confirms the selected valueComponent bound value
blurTriggers when input loses focusComponent instance
focusTriggers when input gains focusComponent instance

Methods

Method NameDescriptionParameter
focusMake input gain focus-