Open14

MUI X DateTimePickerメモ

yoshi0518yoshi0518

基本の表示

https://mui.com/x/react-date-pickers/getting-started/

'use client';

import { LocalizationProvider, DatePicker } from '@mui/x-date-pickers';
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import clsx from 'clsx';
import React from 'react';

import './global.css';

/** Date(共通UI) */
export const CommonDatePicker = React.memo(function CommonDatePicker() {
  return (
    <LocalizationProvider dateAdapter={AdapterDayjs}>
      <DatePicker />
    </LocalizationProvider>
  );
});

yoshi0518yoshi0518

時刻選択パターン

時分(デフォルト)

<TimePicker />

時分秒

<TimePicker views={['hours', 'minutes', 'seconds']} />

分秒

<TimePicker views={['minutes', 'seconds']} />

yoshi0518yoshi0518

時刻選択 24時間表示

HH: 24時間表示

<TimePicker views={['hours', 'minutes', 'seconds']} format="HH:mm:ss" />

hh: 12時間表記

<TimePicker views={['hours', 'minutes', 'seconds']} format="A hh:mm:ss" />

yoshi0518yoshi0518

#時刻選択 24時間選択

<TimePicker views={['hours', 'minutes', 'seconds']} format="HH:mm:ss" ampm={false} />