MUI 数据网格类型:日期,默认格式为“YYYY-MM-DD”

问题描述 投票:0回答:1

我正在尝试格式化我们在数据网格的日期列中显示的默认日期格式。

我可以在选择日期后按照我的预期使用更改格式

      valueFormatter: (params) => moment(params?.value).format("YYYY-MM-DD"),

但是,我想在日期选择器中显示为“YYYY-MM-DD”。但是,默认情况下它显示“dd-mm-yyyy”,如图所示。

<<<<<

{
      field: "discussed_date",
      headerName: "Date(YYYY-MM-DD)",
      type: "date",
      editable: true,
      resizable: true,
      minWidth: 180,
      width: 180,
      format:"YYYY-MM-DD", //tried this, not working
      views:["year", "month", "day"]  //tried this not working
      // inputFormat:"YYYY/MM/DD"   
      },
reactjs material-ui datagrid date-format react-grid-layout
1个回答
0
投票

我正在使用 MUI v5。试试这个:(您可以将“fr-CA”更改为其他语言环境)

{
    field: 'dataRef',
    headerName: 'Date(YYYY-MM-DD)',
    type: 'date',
    editable: true,
    resizable: true,
    minWidth: 180,
    width: 180,
    valueFormatter: ({ value }) => new Intl.DateTimeFormat('fr-CA', {
        year: 'numeric', month: '2-digit', day: '2-digit'
    }).format(value)
}
© www.soinside.com 2019 - 2024. All rights reserved.