Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change material-ui timepicker to 24 hour format

Currently using a Timepicker from material-ui. I have it set to type="time" which allows me to select through times during the day in 12 hours with a AM / PM option. I would like to have my picker with a 24-hour format which would remove the AM/PM option. I've looked in the material-ui documentation and could not find anything that could handle this.

Sandbox

Current code:

    <form className={classes.container} noValidate>
      <TextField
        id="time"
        label="Alarm clock"
        type="time"
        className={classes.textField}
        InputLabelProps={{
          shrink: true
        }}
        inputProps={{
          step: 900 // 5 min
        }}
      />
    </form>
like image 630
neoslo Avatar asked Feb 06 '20 00:02

neoslo


2 Answers

They seem to be reccomending using @material-ui/pickers

https://material-ui-pickers.dev/api/TimePicker

import { TimePicker } from '@material-ui/pickers'

the following option should do it for you

ampm={false}
   <TimePicker
     clearable
     ampm={false}
     label="24 hours"
     value={selectedDate}
     onChange={handleDateChange}
   />

If you need to use the native picker check out this post HTML input time in 24 format

like image 194
Andrew Avatar answered Sep 25 '22 03:09

Andrew


If you use Material UI

import DateTimePicker from '@mui/lab/DateTimePicker';


<DateTimePicker
label="Дуусах өдөр"
value={dateValue}
ampm={false} // use this row
onChange={handleChangeDate}
renderInput={(params) => <TextField {...params} />}
/>

But we need to avoid @mui/labs components

like image 44
Bayrsaihan Tergeltengis Avatar answered Sep 23 '22 03:09

Bayrsaihan Tergeltengis