admin管理员组

文章数量:1406063

I am working on a system where I am asked to set an exact time point with this format dd/MM/yyyy HH:mm:ss, the problem is that I can't find a way to add a datetimepicker that contains all that at once, The ponent MUI's DateTimePicker is very ugly, and I like the native datepicker (it's the one I'd like to use) but I've only been able to choose the full date, hours, minutes but not seconds. Is there a way to do it? So far my code is like this (I also attach an image of the result):

<TextField
 id="datetime-local"
 label="Next appointment"
 type="datetime-local"
 defaultValue={ new Date() }
 InputLabelProps={{shrink: true,}}
/>

This is what I have so far

I am working on a system where I am asked to set an exact time point with this format dd/MM/yyyy HH:mm:ss, the problem is that I can't find a way to add a datetimepicker that contains all that at once, The ponent MUI's DateTimePicker is very ugly, and I like the native datepicker (it's the one I'd like to use) but I've only been able to choose the full date, hours, minutes but not seconds. Is there a way to do it? So far my code is like this (I also attach an image of the result):

<TextField
 id="datetime-local"
 label="Next appointment"
 type="datetime-local"
 defaultValue={ new Date() }
 InputLabelProps={{shrink: true,}}
/>

This is what I have so far

Share Improve this question asked Jan 15, 2022 at 7:22 Luis SandovalLuis Sandoval 111 silver badge2 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

material-ui has pickers: @material-ui/pickers

You can use it with format option:

import React, { useState } from 'react';
import { DateTimePicker } from '@material-ui/pickers';

function App() {
  const [selectedDate, handleDateChange] = useState(new Date());

  return (
      <DateTimePicker format="dd-MM-yyyy HH:mm:ss" value={selectedDate} onChange={handleDateChange} />
  );
}

export default App;

You can incorporate these views within your DesktopDateTimePicker ponent as follows:

  <DesktopDateTimePicker
      views={['year','month','day','hours', 'minutes', 'seconds']} />

This configuration allows users to select years, months, days, hours, minutes, and seconds within the DesktopDateTimePicker ponent.

本文标签: javascriptDateTimePicker with datehoursminutes and secondsStack Overflow